String 存储如下:procedure TForm1.Button3Click(Sender: TObject);
var
tf: File;
bSingle: Byte;
op,P: PChar;
BufLen: integer;
TempTextContent: String;
DocDataBuf : array[0..10240] of char; //----保存图元文件的数据。
begin
AssignFile(tf, 'd:/test.txt');
ReWrite(tf, 1); BufLen := 0;
Fillchar(DocDataBuf, sizeof(DocDataBuf), 0); p := DocDataBuf;
op := p; bSingle := 5;
Move(bSingle, p^, sizeof(bSingle));
p := p + sizeof(bSingle); TempTextContent := ‘Text'; Move(TempTextContent, p^, bSingle);
p := p + bSingle; BufLen := p - op; BlockWrite(tf, DocDataBuf, BufLen); CloseFile(tf);
end;读取如:procedure TForm1.Button4Click(Sender: TObject);
var
tf: File;
bSingle: Byte;
op,P: PChar;
BufLen: integer;
TempTextContent: String;
DocDataBuf : array[0..10240] of char; //----保存图元文件的数据。
begin AssignFile(tf, 'd:/test.txt'); Reset(tf, 1); Fillchar(DocDataBuf, sizeof(DocDataBuf), 0);
BlockRead(tf, DocDataBuf, 6, BufLen); P := DocDataBuf; bSingle := 0;
move(p^, bSingle, sizeOf(bSingle));
P := P + sizeof(bSingle); SetLength(TempTextContent, bSingle);
move(P^, TempTextContent, bSingle);
P := P + bSingle; ShowMessage('TempTextContent is ' + TempTextContent); CloseFile(tf);end;
String数据 存储,读取 未报错。数据正常,关闭程序时,报内存错误。
不知,String数据 如何正常读取? 请指教
var
tf: File;
bSingle: Byte;
op,P: PChar;
BufLen: integer;
TempTextContent: String;
DocDataBuf : array[0..10240] of char; //----保存图元文件的数据。
begin
AssignFile(tf, 'd:/test.txt');
ReWrite(tf, 1); BufLen := 0;
Fillchar(DocDataBuf, sizeof(DocDataBuf), 0); p := DocDataBuf;
op := p; bSingle := 5;
Move(bSingle, p^, sizeof(bSingle));
p := p + sizeof(bSingle); TempTextContent := ‘Text'; Move(TempTextContent, p^, bSingle);
p := p + bSingle; BufLen := p - op; BlockWrite(tf, DocDataBuf, BufLen); CloseFile(tf);
end;读取如:procedure TForm1.Button4Click(Sender: TObject);
var
tf: File;
bSingle: Byte;
op,P: PChar;
BufLen: integer;
TempTextContent: String;
DocDataBuf : array[0..10240] of char; //----保存图元文件的数据。
begin AssignFile(tf, 'd:/test.txt'); Reset(tf, 1); Fillchar(DocDataBuf, sizeof(DocDataBuf), 0);
BlockRead(tf, DocDataBuf, 6, BufLen); P := DocDataBuf; bSingle := 0;
move(p^, bSingle, sizeOf(bSingle));
P := P + sizeof(bSingle); SetLength(TempTextContent, bSingle);
move(P^, TempTextContent, bSingle);
P := P + bSingle; ShowMessage('TempTextContent is ' + TempTextContent); CloseFile(tf);end;
String数据 存储,读取 未报错。数据正常,关闭程序时,报内存错误。
不知,String数据 如何正常读取? 请指教
解决方案 »
- 怎么给fastreport4里的名称为Memo1的控件赋值??
- Edit保存成图片
- 值得同大家庆祝的一天 大家请进!!!
- 本人刚建一QQ群《数字人生》,希望给大家提供一个各种编程语言交流的平台!欢迎大家加入!!!
- 如何截取一个BMP图象形文件上的一块?
- 您都用delphi制作过什么东西
- 读配置文件是出现的问题!!求救!!!!!!!!!!!!!!!!!!!!
- ---------->>>>>>>>>>>21世纪之惊人大发现:Delphi/BCB编译器之缺陷???
- 哈哈,很菜,但敬请关注!!!!
- 用程序怎么控制图片放大缩小的?
- 静态结构数组循环的问题。
- 求《delphi下深入windows核心编程》实体书
var F: TextFile;
S: string;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
Reset(F);
Readln(F, S); { Read first line of file }
Edit1.Text := S; { Put string in a TEdit control }
CloseFile(F);
end;
end;
procedure TForm1.T_openClick(Sender: TObject);
var
new: TForm2;
f1: textfile;
str: string;
begin
OpenDialog1.Filter :='TXT文件(*.txt)|*.txt|所有文件(*.*)|*.*'; //获取文本文件
if OpenDialog1.Execute then
begin
new:=TForm2.Create(Application);
new.Caption:=OpenDialog1.FileName;
end;
//new.RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName); //加载文件并打开文件,但是手动打开文件,出现一些乱码情况
Assignfile(f1,new.Caption );
if fileexists(new.Caption ) then
Begin
reset(f1);
End;
while not Eof(f1) do
Begin
readln(f1,str);
new.RichEdit1.Lines.Add(str);
End;
closefile(f1);
end;procedure TForm1.N_newClick(Sender: TObject);
var
now: Tform2;
begin
now:=Tform2.Create(Application);
now.Caption :='记事本'+inttostr(MDIChildCount) ;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
//OpenDialog1.Filter:= 'Text Files(*.txt)|*.txt|Rich Type Files(*.rtf)|*.rtf';
SaveDialog1.Filter:='TXT文件(*.txt)|*.txt|所有文件(*.*)|*.*';
//Application.OnHint:=show_text; //显示提示信息
Com_font.Items.AddStrings(Screen.Fonts); //载入字体
end;procedure TForm1.T_saveClick(Sender: TObject); //保存文本
var
f1: textfile;
i: integer;
str: string;
begin
if ActiveMdichild<>nil then
Begin
if FileExists(ActiveMDiChild.Caption ) then
Begin
// (ActiveMDiChild as Tform2).RichEdit1.Lines.SaveToFile((ActiveMDiChild as Tform2).Caption ); 这样保存出现乱吗的情况,采用下面的方式
//判断文件是否存在
assignfile(f1,ActiveMDiChild.Caption );
rewrite(f1);
for i:=0 to (Activemdichild as Tform2).RichEdit1.Lines.Count-1 do
begin
str:=(Activemdichild as Tform2).RichEdit1.Lines[i];
writeln(f1,str);
end;
closefile(f1);
End
Else
N_saveas.Click ;
End;
end;procedure TForm1.N_saveasClick(Sender: TObject);
var
f1: Textfile; //文件变量
i: integer; //循环变量
str: string; //文件内容变量
filename: string; //文件名称变量
begin
if ActiveMDIChild <> nil then //如果有活动的子窗口
begin
SaveDialog1.Filter :='TXT文件(*.txt)|*.txt|所有文件(*.*)|*.*';
SaveDialog1.filename:=(ActiveMDIChild as TForm2).Caption;
ActiveMDichild.Caption:=ActiveMDichild.Caption+'.txt';
// str1:=SaveDialog1.filename+'.txt';
if SaveDialog1.Execute then
begin
//判断保存的文件名是否有重复现象
filename:=Savedialog1.FileName ;
filename:=FileName+'.txt';
if fileexists(filename) then
Begin
if Application.MessageBox(PChar(filename),'覆盖',MB_iconstop+mb_okcancel)=idok then //缺少获取文件路径提示
Begin
assignfile(f1,FileName);
rewrite(f1);
for i:=0 to (Activemdichild as Tform2).RichEdit1.Lines.Count-1 do
begin
str:=(Activemdichild as Tform2).RichEdit1.Lines[i];
writeln(f1,str);
end;
closefile(f1);
End
Else
Begin
// Savedialog1.Execute ;
Begin
filename:=''; //对于重复性的覆盖提示,所以这里应该缺少写函数,实现嵌套作用了/\采用从新调用可以不用写函数维护
N_saveas.Click ;
End;
End;
End
Else
Begin
assignfile(f1,FileName );
rewrite(f1);
for i:=0 to (Activemdichild as Tform2).RichEdit1.Lines.Count-1 do
begin
str:=(Activemdichild as Tform2).RichEdit1.Lines[i];
writeln(f1,str);
end;
closefile(f1);
End;
end;
(ActiveMDiChild as Tform2).Caption :=FileName;
end;
End;