一个困扰我很久的问题!!! information:string;就行了Delphi中的string类型很强大,我们知道普通的字符串长度最大为256个字符,但Delphi中string类型在默认情况下长度可以达到2G。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果你使用了String类型,那么就不能使用Packed关键字。你也可以使用微软提供的ISTREAM和ISTROAGE接口进行结构化的数据存取!!! ansistring 是没有长度限制的字符串类型,string默认为ansistring类型,所以直接定义为string 就行了! type TRecord=packed recod name:string[20]; information:array[0..1023] of char; end; 定义为string没有错,在D6中我也经常这样做。不过我不知道在D5中可不可以。事实上从你的需求来看,根本就不需要定长的记录。 强烈建议用字符数组.array[0..511] of char ////pchar type tt=packed record t:string; end;ai!!!!!我怎么运行通过了??????????????????? 通各位高手的提示,问题已经解决,但是又发现一个问题,有可能出现乱码,源码如下:unit SaveDB;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TRecord=packed record name:string[20]; information:array[0..1023] of char; end; RF= file of TRecord;type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Memo2: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; records:TRecord; RFS:RF;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);var i:integer;begin AssignFile(RFS, 'c:\a.txt'); if FileExists('c:\a.txt') then Reset(RFS) else Rewrite(RFS); records.name :='asdfasdf'; for i:=0 to 1023 do records.information[i] :=Pchar(copy(Memo1.Text,i,1))^; Write(RFS, records); seek(rfs,0); read(rfs,records); Memo2.Text:=records.information;end;end. 数据并发问题? showmessage问题 如何用DELPHI来读数据? 一个令人困惑的问题,来者有分 如何将一个32*32的图片变成一个64*64的图片 在学习devexpress系列后,总结的3大问题,希望大家能解决! 请教:关于TMemoryStream的问题,急,很奇怪,在线等待(100分) ??????????? Query1的filter的属性设置问题 关于DBGrid查询,急需!!!急需!!! 这条sql语句为什么会出错 dbgrid响应删除记录事件是哪个?是onKeyPress吗?
所以直接定义为string 就行了!
TRecord=packed recod
name:string[20];
information:array[0..1023] of char;
end;
事实上从你的需求来看,根本就不需要定长的记录。
强烈建议用字符数组.array[0..511] of char ////pchar
tt=packed record
t:string;
end;ai!!!!!我怎么运行通过了???????????????????
源码如下:unit SaveDB;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TRecord=packed record
name:string[20];
information:array[0..1023] of char;
end;
RF= file of TRecord;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
records:TRecord;
RFS:RF;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
AssignFile(RFS, 'c:\a.txt');
if FileExists('c:\a.txt') then
Reset(RFS)
else
Rewrite(RFS);
records.name :='asdfasdf';
for i:=0 to 1023 do
records.information[i] :=Pchar(copy(Memo1.Text,i,1))^; Write(RFS, records);
seek(rfs,0);
read(rfs,records);
Memo2.Text:=records.information;end;end.