为什么要这样转呢?直接定义str:TString100
然后lst.add(pointer(@str));不好吗
然后lst.add(pointer(@str));不好吗
解决方案 »
- windows.pas里面包含的函数是不是未经封装的window api?
- 所有分数求助,在调用的子过程里改变传递过去的动态数组的长度,为什么不可以呢?
- 我遇到拦路虎,帮帮我拉!!!!!!!其实比较简单
- 关于焦点移动问题??此问题不一般!请各位高人来看看.
- 凡是用过ACCESS的兄弟们,进来看看吧,在线两个月了,没有人解决
- D7可以实现这个吗?
- 如何在Delphi的线程中调用中间应用服务器的接口方法?
- pagecontrol切换PAGE时触发什么消息,我想切换时判断一下。。。
- 寻求帮助
- midas 高难度问题,高手请进
- 請問:如何捕捉ADO的錯誤代號?然后顯示自己編寫的錯誤提示.
- 请详细解释GetTickCount的含义
lst.add(pointer(@((str)));
就可以了!
各位应该很清楚Sizeof(String)和sizeof(TString100)的区别有多大吧?而且我的str是从TStringList取出来的。
lst.add(pointer(@((str)));lst.add(pointer(@(str[1])));这些用法都不符合我的要求
lst.add(pointer((TString100(str))));
试试
将str:string;改为str:string[100]问题解决。
str:String;
temp:TString100;
begin
str:='fdfldk';
lst:=TList.Create;
temp:=TString100(str);
lst.add(pointer(@temp));
end;应该能满足你的要求。
This example creates a list object and inserts two records into it. The value of the record fields are written on a paintbox:procedure TForm1.FormButton1Click(Sender: TObject);type
PMyList = ^AList;
AList = record
I: Integer;
C: Char;
end;var MyList: TList;
ARecord: PMyList;
B: Byte;
Y: Word;
begin
MyList := TList.Create;
try
New(ARecord);
ARecord^.I := 100;
ARecord^.C := 'Z';
MyList.Add(ARecord); {Add integer 100 and character Z to list}
New(ARecord);
ARecord^.I := 200;
ARecord^.C := 'X';
MyList.Add(ARecord); {Add integer 200 and character X to list} { Now paint the items onto the paintbox}
Y := 10; {Variable used in TextOut function} for B := 0 to (MyList.Count - 1) do
begin
ARecord := MyList.Items[B];
Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I}
Y := Y + 30; {Increment Y Value again}
Canvas.TextOut(10, Y, ARecord^.C); {Display C}
Y := Y + 30; {Increment Y Value}
end; { Cleanup: must free the list items as well as the list }
for B := 0 to (MyList.Count - 1) do
begin ARecord := MyList.Items[B];
Dispose(ARecord);
end;
finally
MyList.Free;
end;
end;
但要注意添加给TList的指针的有效范围问题。
procedure TSerializedData.SaveLanguage;
var recordStream:TRecordFile;
fileName:string;
i,size:integer;
lst:TList;
tempAry:array of TString100;
begin
fileName:=strDataDir+'\'+CStrLanguageFile; size:=sizeof(TString100);
try
recordStream:=TRecordFile.Create(fileName,fmCreate,size);
lst:=TList.Create;
setLength(tempAry,strsLanguage.Count); for i:=0 to strsLanguage.Count-1 do
begin
tempAry[i]:=TString100(strsLanguage[i]);
lst.Add(pointer(@tempAry[i]));
end; recordStream.WriteRecords(lst);
finally
recordStream.Free;
lst.Free;
end;end;