请帮小弟解释代码意思,谢谢 ( 积分: 50 )

  • 主题发起人 主题发起人 tonynew2002
  • 开始时间 开始时间
T

tonynew2002

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,我是初学者,现在想把一个txt文件用delphi寻入SQL表,
可以详细解释一下以下的代码吗?
小弟先在这里说谢谢
代码部分:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
ado: TADOQuery;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

Function GetStrForSpace(SourceStr :String ; JGZF:char ; Index:integer):String;
var
Pchar1 : pchar;
i , count : integer;
cStr : string;
begin
Count := 0;
Pchar1 := pchar(SourceStr);
cStr := '';
for i:=0 to length(Pchar1)-1 do begin
if pchar1 = JGZF then
begin
Count := Count + 1;
if Count = Index then begin
break;
end;
end
else if Count = Index -1 then cStr := cStr + pchar1;
end;
Result := cStr;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Clear;
memo1.Lines.LoadFromFile('c:/1055.txt');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i,jl:integer;
rq,zh,pzlx,pzh,zy,jdbz,fse,ye,_rq,_rq1,_rq2,_rq3:string;
begin
jl:=memo1.Lines.Count;
i:=1;
while i<=jl-1 do begin
rq:=GetStrForSpace(memo1.Lines.Strings,'|',1);
zh:=Getstrforspace(memo1.Lines.Strings,'|',2);
pzlx:=getstrforspace(memo1.Lines.Strings,'|',3);
pzh:=getstrforspace(memo1.Lines.Strings,'|',4);
zy:=getstrforspace(memo1.Lines.Strings,'|',5);
jdbz:=getstrforspace(memo1.Lines.Strings,'|',6);
fse:=getstrforspace(memo1.Lines.Strings,'|',7);
ado.open;
ado.append;
_rq1:=getstrforspace(rq,'/',1);
_rq2:=getstrforspace(rq,'/',2);
_rq3:=getstrforspace(rq,'/',3);
_rq:=_rq1+'-'+_rq2+'-'+_rq3;
ado.fieldbyname('rq').asdatetime:=strtodatetime(_rq);
ado.fieldbyname('zh').asstring:=zh;
ado.fieldbyname('pzlx').asstring:=pzlx;
ado.fieldbyname('pzh').asstring:=pzh;
ado.fieldbyname('zy').asstring:=zy;
if jdbz='1' then begin
ado.fieldbyname('jffs').asfloat:=strtofloat(fse);
end;
if jdbz='2' then begin
ado.fieldbyname('dffs').asfloat:=strtofloat(fse);
end;
ado.post;
i:=i+1;
end;
end;

end.
 
各位大侠,我是初学者,现在想把一个txt文件用delphi寻入SQL表,
可以详细解释一下以下的代码吗?
小弟先在这里说谢谢
代码部分:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
ado: TADOQuery;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

Function GetStrForSpace(SourceStr :String ; JGZF:char ; Index:integer):String;
var
Pchar1 : pchar;
i , count : integer;
cStr : string;
begin
Count := 0;
Pchar1 := pchar(SourceStr);
cStr := '';
for i:=0 to length(Pchar1)-1 do begin
if pchar1 = JGZF then
begin
Count := Count + 1;
if Count = Index then begin
break;
end;
end
else if Count = Index -1 then cStr := cStr + pchar1;
end;
Result := cStr;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Clear;
memo1.Lines.LoadFromFile('c:/1055.txt');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i,jl:integer;
rq,zh,pzlx,pzh,zy,jdbz,fse,ye,_rq,_rq1,_rq2,_rq3:string;
begin
jl:=memo1.Lines.Count;
i:=1;
while i<=jl-1 do begin
rq:=GetStrForSpace(memo1.Lines.Strings,'|',1);
zh:=Getstrforspace(memo1.Lines.Strings,'|',2);
pzlx:=getstrforspace(memo1.Lines.Strings,'|',3);
pzh:=getstrforspace(memo1.Lines.Strings,'|',4);
zy:=getstrforspace(memo1.Lines.Strings,'|',5);
jdbz:=getstrforspace(memo1.Lines.Strings,'|',6);
fse:=getstrforspace(memo1.Lines.Strings,'|',7);
ado.open;
ado.append;
_rq1:=getstrforspace(rq,'/',1);
_rq2:=getstrforspace(rq,'/',2);
_rq3:=getstrforspace(rq,'/',3);
_rq:=_rq1+'-'+_rq2+'-'+_rq3;
ado.fieldbyname('rq').asdatetime:=strtodatetime(_rq);
ado.fieldbyname('zh').asstring:=zh;
ado.fieldbyname('pzlx').asstring:=pzlx;
ado.fieldbyname('pzh').asstring:=pzh;
ado.fieldbyname('zy').asstring:=zy;
if jdbz='1' then begin
ado.fieldbyname('jffs').asfloat:=strtofloat(fse);
end;
if jdbz='2' then begin
ado.fieldbyname('dffs').asfloat:=strtofloat(fse);
end;
ado.post;
i:=i+1;
end;
end;

end.
 
请各位大侠帮帮忙,谢谢
 
大哥我说句不好听的话
这种代码你都看不懂,看来你够新手的了,这种问题最好你自己看书解决,要不还是不要做程序员
因为实在是很简单,基础的书看完后你就应能看懂
 
后退
顶部