一个困扰我很久的问题!!!

xzhifei 2002-08-15 09:10:43
在delphi中,为了保存一个类型文件,自定义一个记录结构,如:
type
TRecord=packed recod
name:string[20];
information:string[255];
end;

请问,怎么做,才能突破string类型长度最长为255的限制!
...全文
52 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xzhifei 2002-08-15
  • 打赏
  • 举报
回复
通各位高手的提示,问题已经解决,但是又发现一个问题,有可能出现乱码,
源码如下:

unit SaveDB;

interface

uses
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.
del_c_sharp 2002-08-15
  • 打赏
  • 举报
回复
type
tt=packed record
t:string;
end;

ai!!!!!

我怎么运行通过了???????????????????
del_c_sharp 2002-08-15
  • 打赏
  • 举报
回复

强烈建议用字符数组.array[0..511] of char ////pchar
slyse 2002-08-15
  • 打赏
  • 举报
回复
定义为string没有错,在D6中我也经常这样做。不过我不知道在D5中可不可以。
事实上从你的需求来看,根本就不需要定长的记录。
Kingron 2002-08-15
  • 打赏
  • 举报
回复
type
TRecord=packed recod
name:string[20];
information:array[0..1023] of char;
end;
披星戴月 2002-08-15
  • 打赏
  • 举报
回复
ansistring 是没有长度限制的字符串类型,string默认为ansistring类型,
所以直接定义为string 就行了!
xzhifei 2002-08-15
  • 打赏
  • 举报
回复
楼上的兄弟
你那么定义在类型文件中是不行的,因为字符串类型需要长度
Delphi_Li 2002-08-15
  • 打赏
  • 举报
回复
如果你使用了String类型,那么就不能使用Packed关键字。

你也可以使用微软提供的ISTREAM和ISTROAGE接口进行结构化的数据存取!!!
chll 2002-08-15
  • 打赏
  • 举报
回复
information:string;就行了
Delphi中的string类型很强大,我们知道普通的字符串长度最大为256个字符,但Delphi中string类型在默认情况下长度可以达到2G。
xzhifei 2002-08-15
  • 打赏
  • 举报
回复
请问有没有详细的源码,给我看一下!!
票票飞扬 2002-08-15
  • 打赏
  • 举报
回复
WideString

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧