在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type PUpData = ^TUpData; TUpData = record a1: array[1..2] of char; a2: array[1..3] of char; a3: array[1..4] of char; end; type TForm1 = class(TForm) btn1: TButton; btn2: TButton; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} //记录内容赋值给字符串 procedure TForm1.btn1Click(Sender: TObject); var s: string; p: pchar; UpData: TUpData; begin //初始化记录 ZeroMemory(@UpData, SizeOf(UpData)); //赋值 UpData.a1 := 'a1'; UpData.a2 := 'a22'; UpData.a3 := 'a333'; //分配字符串长度 setlength(s, SizeOf(UpData)); //记录内容赋值给字符串 p := StrLCopy(pchar(s), @UpData, SizeOf(UpData)); //显示结果 a1a22a333|9|9 showmessage(s + '|' + InttoStr(length(s)) + '|' + InttoStr(SizeOf(UpData))); end; //字符串内容赋值给记录 procedure TForm1.btn2Click(Sender: TObject); var s: string; p: pchar; UpData: TUpData; begin //初始化记录 ZeroMemory(@UpData, SizeOf(UpData)); //赋值 s := 'sendinfo.suv'; //字符串内容赋值给记录 p := StrLCopy(@UpData, pchar(s), sizeof(TUpData)); //显示结果 sendinfo. showmessage(UpData.a1 + UpData.a2 + UpData.a3); end; end.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论