求delphi byte数组转Pchar的方法?
//直接传递指针就可以了, tempchar := @sbuf;//列个例子,看看区别吧varsbuf : array[0..5] of byte;tempchar : pchar;i : integer;hexstr : string;beginfillchar(sbuf,sizeof(sbuf),0);//初始化sbuf的值,全为0//数组的计算位置,应该是0开始的。
sbuf[0]sbuf[0]:=byte($fc); //帧头sbuf[1]:=byte($01); //命令号sbuf[2]:=byte($00);sbuf[3]:=byte($00);sbuf[4]:=byte($00);sbuf[5]:=byte($AA);tempchar := @sbuf;//直接传递指针就可以了, tempchar := @sbuf;但是,//pchar是字符指针类型,终止字符串操控符号为#0,按F1看帮助说明,google翻译一下//所以,#0后面的数据,以上数据实际上,转换成pchar之后的运算结果只剩2位了,for i := 0 to Length(tempchar) -1 doHexstr := hexstr+' ' +IntTohex(byte(tempchar[i]),2);showmessage(hexstr);fillchar(sbuf,sizeof(sbuf),0);//初始化sbuf的值,全为0tempchar := #1#0#0#0#0#2;copymemory(@sbuf,tempchar,6);//pchar,转array[] of byte//因为运算类型不一样,所以,sbuf的值得是#1#0#0#0#0#2;hexstr := '';for i := 0 to sizeof(sbuf)-1 dohexstr := hexstr+' ' +IntTohex(sbuf[i],2);showmessage(hexstr);
Delphi byte数组如何转换integer
{转换 TBytes 到 Integer}procedure TForm1.Button1Click(Sender: TObject);varbs: TBytes; {TBytes 就是 Byte 的动态数组}i: Integer;begin{它应该和 Integer 一样大小才适合转换}SetLength(bs, 4);bs[0] := $10;bs[1] := $27;bs[2] := 0;bs[3] := 0;{因为 TBytes 是动态数组, 所以它的变量 bs 是个指针; 所以先转换到 PInteger} i := PInteger(bs)^; ShowMessage(IntToStr(i)); {10000}end;{从 Bytes 静态数组到 Integer 的转换会方便些}procedure TForm1.Button2Click(Sender: TObject);varbs: array[0..3] of Byte;i: Integer;beginbs[0] := $10;bs[1] := $27;bs[2] := 0;bs[3] := 0;i := Integer(bs);ShowMessage(IntToStr(i)); {10000}end;{转换到自定义的结构}procedure TForm1.Button3Click(Sender: TObject);typeTData = packed recorda: Integer;b: Word;end;varbs: array[0..5] of Byte; {这个数组应该和结构大小一直}data: TData;beginFillChar(bs, Length(bs), 0);bs[0] := $10;bs[1] := $27;data := TData(bs);ShowMessage(IntToStr(data.a)); {10000}end;{转换给自定义结构的一个成员}procedure TForm1.Button4Click(Sender: TObject);typeTData = packed recorda: Integer;b: Word;end;varbs: array[0..3] of Byte;data: TData;beginFillChar(bs, Length(bs), 0);bs[0] := $10;bs[1] := $27;data.a := Integer(bs);ShowMessage(IntToStr(data.a)); {10000}end;
Delphi字节转换字节数组
你的代码只读出那个字节又没做别的处理,因此不用Read了。
因为你那三个字节都是连续的,因此可以用一个byte数组,如下:varF :File;Buf: array[0..2] of byte;beginAssignFile(F, '2.exe');tryReset(F,1);Buf[0]:=$74;Buf[1]:=$31;Buf[2]:=$5c;seek(F,300938);//从300938开始写3个字节BlockWrite(F, Buf, SizeOf(Buf)); finallyCloseFile(F);end;end;
delphi中怎么将3个byte数组转换成一个字节流?
使用vba来指定保存的文件格式为pdf,当然前提必须已安装MS Office的PDF输出插件(默认应该有)procedure TForm1.btn1Click(Sender: TObject);varwdo,wdoc,wdocs : OleVariant;beginwdo := CreateOleObject('Word.Application');wdocs := wdo.Documents;wdoc := wdocs.Open('d:\test.docx');wdoc.ExportAsFixedFormat(OutputFileName:='d:\test.pdf', ExportFormat:=17);//查word的宏帮助{ OpenAfterExport:='True', OptimizeFor:='wdExportOptimizeForPrint', Range:='wdExportAllDocument', From:=1, To:=1, Item:='wdExportDocumentContent',IncludeDocProps:='True', KeepIRM:='True', CreateBookmarks:='wdExportCreateNoBookmarks', DocStructureTags:='True', BitmapMissingFonts:='True', UseISO19005_1:='False'); }end;
delphi 字节数组转字符串问题
procedure TForm1.Button1Click(Sender: TObject);varshowstr:string;ay: array[0..2] of byte;i:integer;beginay[0] := $01;ay[1] := $03;ay[2] := $0b;for i:=0 to 2 doshowstr:=showstr + inttohex(ay[i],2); // _GetByte(inBuf[i]);showmessage(showstr);end;
Delphi 中,Byte数组如何赋值呢?
例子程序:{$apptype console}PROGRAM exp;var a:array [1..10] of byte=(1,3,5,7,9,2,4,6,8,10);i:integer;beginfor i:=1 to 10 do writeln(a[i]);end.运行结果:E:\ygb>dcc32 a.dprBorland Delphi Version 15.0Copyright (c) 1983,2002 Borland Software Corporationa.dpr(8)9 lines, 0.12 seconds, 10636 bytes code, 1813 bytes data.E:\ygb>dcc32 a.dprBorland Delphi Version 15.0Copyright (c) 1983,2002 Borland Software Corporationa.dpr(7)8 lines, 0.05 seconds, 10636 bytes code, 1813 bytes data.E:\ygb>a.exe13579246810
Delphi怎么把一个CHAR 转换为 Byte形请高手指点
语言中没有byte这种类型。
也就是无符号的一个字节。
它将一个字节的8位全占用了。
因为Unicode要占用两个字节。
byte类型是最自由的一种。
它就占用一个字节。
而存储一个ANSI字符只需一个字节。
char 是字符型byte 是字节型(0 - 255)在参与算术运算是char类型会自动转为整型;如字符A会转为对应ASCII码65. char是用来表示一个字符。
注意,强调是ANSI字符,而不是Unicode字符,而不是一个字,因为一个字要占用两个字节,但没有定义这个字节拿来干什么。
char定义为一个Unsigned Byte类型。
可以表示的数据范围是0到255之间,这是计算机中存储信息的单位...
delphi中把查询出来的数据导入word中?
我将我的商用《旅行社管理系统》的 发团通知 部分奉献给您,望对您有所帮助。
procedure TFrmMain.N327Click(Sender: TObject); var FWord :Variant; FDoc :Variant; strSQL :string; begin //首先创造对象,如果出现异常就做出提示 try FWord := CreateOleObject('Word.Application'); //WOrd程序的执行是否可见,值为false时,程序在后台运行。
FWord.Visible := True; except messagebox(0,'创建word对象失败!','警告',MB_OK+MB_ICONINFORMATION); exit; end; strSQL :='select * From "B_T_Company_Infor"'; with dm.ClientDataSet_Temp do begin if Active then Active:=False; CommandText:=strSQL; Open; end; //现在打开的Word中,创建一个新的页面,然后在其中键入需要的内容 try FDOC :=FWord.Documents.Add; {对于Word的新页面} FWord.Selection.Font.Name :='宋体'; FWord.Selection.Font.Size :=20; FWord.Selection.Font.Bold :=2; FWord.Selection.paragraphs.Alignment := wdAlignParagraphCenter; FWord.Selection.TypeText(dm.ClientDataSet_Temp.Fields[0].AsString); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph; FWord.Selection.paragraphs.Alignment := wdAlignParagraphLeft; FWord.Selection.Font.Size :=12; FWord.Selection.Font.Bold :=0; FWord.Selection.TypeText(' 现将我社组团部的'); FWord.Selection.TypeText(' '); FWord.Selection.TypeText('团计划发出,各地请按下列行程做接待,并及早落实'+ '团队计划和选派优秀导游员。
各地代订住宿、火车票、机票务必安排好接待,日程'+ '如有变更,及时与下站接待社或本社联系,各地接团时请举【'+ dm.ClientDataSet_Temp.Fields[0].AsString+'】接站牌。
'); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('请速回传真确认,谢谢合作!'); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('人数:'); FWord.Selection.TypeText('人数:'); FWord.Selection.TypeText('国籍:'); FWord.Selection.TypeText('国籍:'); FWord.Selection.TypeText('等级:'); FWord.Selection.TypeText('等级:'); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('这里是团队安排'); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('TO: '); FWord.Selection.TypeText('12345678901234567890'); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('TEL: '); FWord.Selection.TypeText('12345678901234567890'); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('FAX: '); FWord.Selection.TypeText('12345678901234567890'); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('______________________________________________'); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('FROM: '); FWord.Selection.TypeText(dm.ClientDataSet_Temp.Fields[0].AsString); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('TEL: '); FWord.Selection.TypeText(dm.ClientDataSet_Temp.Fields[3].AsString); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText('FAX: '); FWord.Selection.TypeText(dm.ClientDataSet_Temp.Fields[4].AsString); FWord.Selection.Typeparagraph;//换行 Except on e: Exception do Messagebox(0,Pchar(e.Message),'警告',MB_OK+MB_ICONINFORMATION); end; //保存文档 FWord.Caption := '组团计划保存在: '+ExtractFilePath(application.ExeName)+'Reports\GroupPlan.doc'; FDOC.SaveAS(ExtractFilePath(application.ExeName)+'Reports\GroupPlan.doc'); if messagebox(0,'组团计划已经保存成功!'+chr(13)+chr(13)+ '单击【确定】退出Word,返回到程序中!','您确信要退出Word吗?', MB_YESNO+MB_ICONINFORMATION+MB_DEFBUTTON2)=IDYES then begin FWord.Quit; FWord := Unassigned; end; end; ----------------------------- Delphi与Word之间的融合技术(1) 一、VBA代码含义 Microsoft Word是一个集成化环境,是美国微软公司的字处理系统,但是它决不仅仅是一个字处理系统,它集成了Microsoft Visual Basic,可以通过编程来实现对Word功能的扩展。
Microsoft Visual Basic在word中的代码即Word的宏,通过编写Word宏,可实现一些文档处理的自动化,如实现文档的自动备份、存盘等,可扩展Word文档的功能,因此,能够充分利用Word的特性,甚至使Word成为自己软件的一部分。
Word的宏既有有利的一部分,因为它能够帮助我们实现文档的自动化,但是Word的宏也不是纯粹的有利,有时它可能危害我们的文档、计算机系统甚 至网络,从最开始的Taiwan NO1宏病毒到现在的...
转载请注明出处51数据库 » delphi word转byte