文件平台我的学习生涯(Delphi篇) - 00

最近一直在查找文件平台之类的问题,今天正好有机会和大家共享一下.

    写在开篇!

    很高兴在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程序员最最最最最痛苦的事儿是啥,知道不? 就是,狗日的客户又回来了,程序给删没了!

转载于:https://www.cnblogs.com/jiangu66/archive/2013/05/12/3074168.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值