查错(关于记录/指针) 分少可以再加 ( 积分: 50 )

  • 主题发起人 主题发起人 zgl198171
  • 开始时间 开始时间
Z

zgl198171

Unregistered / Unconfirmed
GUEST, unregistred user!
我查了很多资料就是不能解决问题啊,所以请教各位哥哥帮我查一下,不甚感激!

下面的程序完成创建表.
添加字段程序快:
procedure TFrm_GSFactorSet.Button1Click(Sender: TObject);
var
FieldPtr:PFieldRec;
begin
new(FieldPtr);
FieldPtr^.Name:=Trim(Edit3.Text);
FieldPtr^.FType:=Trim(ComboBox2.Text);
FieldPtr^.FNumber:=StrToInt(MaskEdit1.text);
FieldPtr^.IsNull:=CheckBox1.Checked;
//初始Len为1

SetLength(FieldRec,Len);
FieldRec[len-1]:=FieldPtr
//有没有错?????

INC(Len);
dispose(FieldPtr);

Edit3.Text:='';
Edit3.SetFocus;
end;
测试块:
var
I:integer;
begin
For I:=Low(FieldRec) to High(FieldRec) do
begin //有错,得不到正确的结果
ShowMessage(FieldRec^.name)
// +'_'+(FieldRec^).FType
end;

end;
保存模块:
procedure TFrm_GSFactorSet.Button2Click(Sender: TObject);
var
aq:TADOQUery;
i:Integer;
begin
aq:=TADOQuery.Create(nil);
aq.Connection:=MYDM.ADOConnection1;
Try
aq.Close;
aq.SQL.Clear;
aq.SQL.Add('Create Table '+' '+edit1.Text);
aq.SQL.Add('(');
For i:=Low(FieldRec) to High(FieldRec)-1 do
begin
if (FieldRec)^.IsNull then
aq.SQL.Add((FieldRec)^.name+' '+(FieldRec)^.FType+'('+inttostr((FieldRec)^.Fnumber)+' '+' Null'+',')
else
aq.SQL.Add((FieldRec)^.name+' '+(FieldRec)^.FType+'('+inttostr((FieldRec)^.Fnumber)+' '+' Not Null'+',') ;
end;
i:=High(FieldRec);
if (FieldRec)^.IsNull then
aq.SQL.Add((FieldRec)^.name+' '+(FieldRec)^.FType+'('+inttostr((FieldRec)^.Fnumber)+' '+' Null')
else
aq.SQL.Add((FieldRec)^.name+' '+(FieldRec)^.FType+'('+inttostr((FieldRec)^.Fnumber)+' '+' Not Null') ;
aq.SQL.Add(')') ;
aq.ExecSQL;
showmessage('创建表成功!')
except
end;
end;
 
我查了很多资料就是不能解决问题啊,所以请教各位哥哥帮我查一下,不甚感激!

下面的程序完成创建表.
添加字段程序快:
procedure TFrm_GSFactorSet.Button1Click(Sender: TObject);
var
FieldPtr:PFieldRec;
begin
new(FieldPtr);
FieldPtr^.Name:=Trim(Edit3.Text);
FieldPtr^.FType:=Trim(ComboBox2.Text);
FieldPtr^.FNumber:=StrToInt(MaskEdit1.text);
FieldPtr^.IsNull:=CheckBox1.Checked;
//初始Len为1

SetLength(FieldRec,Len);
FieldRec[len-1]:=FieldPtr
//有没有错?????

INC(Len);
dispose(FieldPtr);

Edit3.Text:='';
Edit3.SetFocus;
end;
测试块:
var
I:integer;
begin
For I:=Low(FieldRec) to High(FieldRec) do
begin //有错,得不到正确的结果
ShowMessage(FieldRec^.name)
// +'_'+(FieldRec^).FType
end;

end;
保存模块:
procedure TFrm_GSFactorSet.Button2Click(Sender: TObject);
var
aq:TADOQUery;
i:Integer;
begin
aq:=TADOQuery.Create(nil);
aq.Connection:=MYDM.ADOConnection1;
Try
aq.Close;
aq.SQL.Clear;
aq.SQL.Add('Create Table '+' '+edit1.Text);
aq.SQL.Add('(');
For i:=Low(FieldRec) to High(FieldRec)-1 do
begin
if (FieldRec)^.IsNull then
aq.SQL.Add((FieldRec)^.name+' '+(FieldRec)^.FType+'('+inttostr((FieldRec)^.Fnumber)+' '+' Null'+',')
else
aq.SQL.Add((FieldRec)^.name+' '+(FieldRec)^.FType+'('+inttostr((FieldRec)^.Fnumber)+' '+' Not Null'+',') ;
end;
i:=High(FieldRec);
if (FieldRec)^.IsNull then
aq.SQL.Add((FieldRec)^.name+' '+(FieldRec)^.FType+'('+inttostr((FieldRec)^.Fnumber)+' '+' Null')
else
aq.SQL.Add((FieldRec)^.name+' '+(FieldRec)^.FType+'('+inttostr((FieldRec)^.Fnumber)+' '+' Not Null') ;
aq.SQL.Add(')') ;
aq.ExecSQL;
showmessage('创建表成功!')
except
end;
end;
 
procedure TFrm_GSFactorSet.Button1Click(Sender: TObject);
var
FieldPtr:PFieldRec;
begin
new(FieldPtr);
FieldPtr^.Name:=Trim(Edit3.Text);
FieldPtr^.FType:=Trim(ComboBox2.Text);
FieldPtr^.FNumber:=StrToInt(MaskEdit1.text);
FieldPtr^.IsNull:=CheckBox1.Checked;
//初始Len为1

SetLength(FieldRec,Len);
FieldRec[len-1]:=FieldPtr
//有没有错?????
//初始为一就没有错误
INC(Len);
dispose(FieldPtr)
//这里不要释放,到不需要的时候再释放

Edit3.Text:='';
Edit3.SetFocus;
end;
--------------------------------------------------------------------------
var
I:integer;
begin
For I:=Low(FieldRec) to High(FieldRec) do
begin //有错,得不到正确的结果
ShowMessage(FieldRec^.name)
// +'_'+(FieldRec^).FType
end;
//你已经把指针释放了,FieldRec^.name就不存在,当然要出错
//FieldRec是不是为array of PFieldRec类型啊!
end;
 
是啊。...定义如下:
pFieldRec=^TFieldRec;
TFieldRec=Record
name:String[30];
FType:String[16];
Fnumber:Integer;
IsNull:Boolean;
end;
var
Len:Integer;
FieldRec:array of PFieldRec;

procedure TFrm_GSFactorSet.Button1Click(Sender: TObject);
var
FieldPtr:PFieldRec;
begin
new(FieldPtr);
FieldPtr^.Name:=Trim(Edit3.Text);
FieldPtr^.FType:=Trim(ComboBox2.Text);
FieldPtr^.FNumber:=StrToInt(MaskEdit1.text);
FieldPtr^.IsNull:=CheckBox1.Checked;
//初始Len为1

SetLength(FieldRec,Len);
FieldRec[len-1]:=FieldPtr
//有没有错?????///我这里是把上面的负值给数组啊....不置恰当否....要是这样的话,后面的dispose应该没错把
//初始为一就没有错误
INC(Len);
dispose(FieldPtr)
//这里

Edit3.Text:='';
Edit3.SetFocus;
end;
 
感谢vciner,再试后给你加分
 
接受答案了.
 
后退
顶部