最近一直在查找文件平台之类的问题,今天正好有机会和大家共享一下.
写在开篇!
很高兴在CSDN这个平台与宽大的开发者交流心得。
毕业后,一直在学习Delphi。说来也许好笑:上学时,Pascal测验不及格!所以,天天看看Pascal的书。
04进了一家私企应用就是Delphi。使自己对在Windows平台应用Delphi进行C/S有了坚定的信念!
直到现在,我还是以为在Windows平台最好的C/S开发工具非Delphi莫属!
-------------------------------------------------------------------------------------------------俏丽分割线---------------------------
年代:2005
文件:my0501.zip
效果如下图:
Unit1.pas
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Memo1: TMemo; OpenDialog1: TOpenDialog; Panel1: TPanel; Panel2: TPanel; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; filenames:string; function GetTextFromFile(AFile : String; var ReturnString : string) : boolean; implementation {$R *.dfm} function GetTextFromFile(AFile : String; var ReturnString : string) : boolean; var FileStream : TFileStream; begin result := false; if not fileexists(AFile) then exit; FileStream := TFileStream.Create(AFile,fmopenreadwrite); try if FileStream.Size > 0 then begin SetLength(ReturnString,FileStream.size); FileStream.Read(ReturnString[1],FileStream.Size); result := true; end finally FileStream.Free; end; end; procedure TForm1.Button1Click(Sender: TObject); var s : string; buffer1:PChar; begin try OpenDialog1.InitialDir:='d:\'; OpenDialog1.Filter:='数据文件(*.xbf)| *.xbf'; if OpenDialog1.Execute then begin filenames:=OpenDialog1.FileName; end; except end; if GetTextFromFile(filenames,s) then begin // Label1.caption := s; or assign the text to a Label Memo1.text := s; end; end; procedure TForm1.Button2Click(Sender: TObject); begin Application.Terminate; end; procedure TForm1.FormCreate(Sender: TObject); begin Form1.Caption:='打开数据文件'; form1.BorderStyle:=bsSingle; end; procedure TForm1.Button3Click(Sender: TObject); begin Memo1.Lines.SaveToFile(filenames); end; procedure TForm1.Button4Click(Sender: TObject); var sfi,si:integer; buff:array [0..4096] of byte; s:string; begin try OpenDialog1.InitialDir:='d:\'; OpenDialog1.Filter:='报文文件(*.rep)| *.rep'; if OpenDialog1.Execute then begin filenames:=OpenDialog1.FileName; end; except end; //sfi:=FileOpen(filenames,fmOpenReadWrite); //if sfi=-1 then exit; //文件不存在 // FileSeek(sfi,where,0); // 指定要读位置,0:从文件头计起 //si:=FileRead(sfi,buff,4096); //读入多少字节的数据 //FileSeek(sfi,where,0); // 指定要写位置,0:从文件头计起,2:从文件尾倒数 //filewrite(sfi,buff,4096); //FileClose(sfi); if GetTextFromFile(filenames,s) then begin // Label1.caption := s; or assign the text to a Label Memo1.text := s; end; end; procedure TForm1.Button5Click(Sender: TObject); var Buffer: PChar; begin GetMem(Buffer,Length(Memo1.Text) + Length(Memo1.Text) + 1); StrCopy(Buffer, PChar(Memo1.Text)); StrCat(Buffer, PChar(Memo1.Text)); Memo1.Text := Buffer; FreeMem(Buffer); end; end.
文章结束给大家分享下程序员的一些笑话语录:
小沈阳版程序员~~~ \n程序员其实可痛苦的了......需求一做一改,一个月就过去了;嚎~ \n需求再一改一调,一季度就过去了;嚎~ \n程序员最痛苦的事儿是啥,知道不?就是,程序没做完,需求又改了; \n程序员最最痛苦的事儿是啥,知道不? 就是,系统好不容易做完了,方案全改了; \n程序员最最最痛苦的事儿是啥,知道不? 就是,系统做完了,狗日的客户跑了; \n程序员最最最最最痛苦的事儿是啥,知道不? 就是,狗日的客户又回来了,程序给删没了!