mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 19:39:18 +02:00
ideintf: fix add fields editor - don't use TFieldDef references since dataset can rebuild them and we get pointers to the wrong memory areas
git-svn-id: trunk@22256 -
This commit is contained in:
parent
cc6b1224f5
commit
21709ba4c4
@ -7,7 +7,7 @@ object FieldsListFrm: TFieldsListFrm
|
||||
Caption = 'FieldsListFrm'
|
||||
ClientHeight = 271
|
||||
ClientWidth = 173
|
||||
LCLVersion = '0.9.25'
|
||||
LCLVersion = '0.9.29'
|
||||
object BitBtnOk: TBitBtn
|
||||
Left = 9
|
||||
Height = 25
|
||||
@ -36,12 +36,14 @@ object FieldsListFrm: TFieldsListFrm
|
||||
TabOrder = 1
|
||||
end
|
||||
object ListBox1: TListBox
|
||||
Left = 0
|
||||
Height = 232
|
||||
Top = 0
|
||||
Width = 173
|
||||
Align = alTop
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
ItemHeight = 0
|
||||
MultiSelect = True
|
||||
TabOrder = 2
|
||||
TopIndex = -1
|
||||
end
|
||||
end
|
||||
|
@ -4,26 +4,14 @@ LazarusResources.Add('TFieldsListFrm','FORMDATA',[
|
||||
'TPF0'#14'TFieldsListFrm'#13'FieldsListFrm'#4'Left'#3'f'#1#6'Height'#3#15#1#3
|
||||
+'Top'#2'c'#5'Width'#3#173#0#13'ActiveControl'#7#8'BitBtnOk'#7'Caption'#6#13
|
||||
+'FieldsListFrm'#12'ClientHeight'#3#15#1#11'ClientWidth'#3#173#0#10'LCLVersio'
|
||||
+'n'#6#6'0.9.25'#0#7'TBitBtn'#8'BitBtnOk'#4'Left'#2#9#6'Height'#2#25#3'Top'#3
|
||||
+'n'#6#6'0.9.29'#0#7'TBitBtn'#8'BitBtnOk'#4'Left'#2#9#6'Height'#2#25#3'Top'#3
|
||||
+#241#0#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#7'&C'
|
||||
+'reate'#7'Default'#9#4'Kind'#7#4'bkOK'#11'ModalResult'#2#1#9'NumGlyphs'#2#0#7
|
||||
+'OnClick'#7#13'BitBtnOkClick'#8'TabOrder'#2#0#0#0#7'TBitBtn'#12'BitBtnCancel'
|
||||
+#4'Left'#2'Y'#6'Height'#2#25#3'Top'#3#241#0#5'Width'#2'K'#7'Anchors'#11#6'ak'
|
||||
+'Left'#8'akBottom'#0#6'Cancel'#9#7'Caption'#6#6'Cancel'#4'Kind'#7#8'bkCancel'
|
||||
+#11'ModalResult'#2#2#9'NumGlyphs'#2#0#8'TabOrder'#2#1#0#0#8'TListBox'#8'List'
|
||||
+'Box1'#6'Height'#3#232#0#5'Width'#3#173#0#5'Align'#7#5'alTop'#7'Anchors'#11#5
|
||||
+'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#11'MultiSelect'#9#8'TabOrder'#2#2
|
||||
+#8'TopIndex'#2#255#0#0#0#14'TFieldsListFrm'#13'FieldsListFrm'#4'Left'#3'f'#1
|
||||
+#6'Height'#3#15#1#3'Top'#2'c'#5'Width'#3#173#0#13'ActiveControl'#7#8'BitBtnO'
|
||||
+'k'#7'Caption'#6#13'FieldsListFrm'#12'ClientHeight'#3#15#1#11'ClientWidth'#3
|
||||
+#173#0#10'LCLVersion'#6#6'0.9.25'#0#7'TBitBtn'#8'BitBtnOk'#4'Left'#2#9#6'Hei'
|
||||
+'ght'#2#25#3'Top'#3#241#0#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akBottom'#0
|
||||
+#7'Caption'#6#7'&Create'#7'Default'#9#4'Kind'#7#4'bkOK'#11'ModalResult'#2#1#9
|
||||
+'NumGlyphs'#2#0#7'OnClick'#7#13'BitBtnOkClick'#8'TabOrder'#2#0#0#0#7'TBitBtn'
|
||||
+#12'BitBtnCancel'#4'Left'#2'Y'#6'Height'#2#25#3'Top'#3#241#0#5'Width'#2'K'#7
|
||||
+'Anchors'#11#6'akLeft'#8'akBottom'#0#6'Cancel'#9#7'Caption'#6#6'Cancel'#4'Ki'
|
||||
+'nd'#7#8'bkCancel'#11'ModalResult'#2#2#9'NumGlyphs'#2#0#8'TabOrder'#2#1#0#0#8
|
||||
+'TListBox'#8'ListBox1'#6'Height'#3#232#0#5'Width'#3#173#0#5'Align'#7#5'alTop'
|
||||
+#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#11'MultiSelect'#9
|
||||
+#8'TabOrder'#2#2#8'TopIndex'#2#255#0#0#0
|
||||
+'Box1'#4'Left'#2#0#6'Height'#3#232#0#3'Top'#2#0#5'Width'#3#173#0#5'Align'#7#5
|
||||
+'alTop'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#10'ItemHei'
|
||||
+'ght'#2#0#11'MultiSelect'#9#8'TabOrder'#2#2#0#0#0
|
||||
]);
|
||||
|
@ -68,6 +68,7 @@ var
|
||||
NewField: TField;
|
||||
fModified: boolean;
|
||||
PreActive: boolean;
|
||||
FieldDef: TFieldDef;
|
||||
|
||||
function CreateFieldName(Owner:TComponent;const AName:string):string;
|
||||
var
|
||||
@ -92,21 +93,24 @@ begin
|
||||
LinkDataSet.Active := False;
|
||||
fModified := False;
|
||||
for i := 0 to ListBox1.Items.Count - 1 do
|
||||
begin
|
||||
if ListBox1.Selected[i] and (LinkDataset.FindField(ListBox1.Items[i]) = nil) then
|
||||
begin
|
||||
if ListBox1.Selected[i] And (LinkDataset.FindField(ListBox1.Items[i]) = Nil) then
|
||||
begin
|
||||
NewField := TFieldDef(ListBox1.Items.Objects[i]).CreateField(LinkDataset.Owner);
|
||||
FieldDef := LinkDataset.FieldDefs.Find(ListBox1.Items[i]);
|
||||
if FieldDef = nil then
|
||||
Continue;
|
||||
NewField := FieldDef.CreateField(LinkDataset.Owner);
|
||||
NewField.Name := CreateFieldName(LinkDataset.Owner, LinkDataset.Name + NewField.FieldName);
|
||||
FDesigner.PropertyEditorHook.PersistentAdded(NewField, True);
|
||||
fModified := True;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
if fModified then FDesigner.Modified;
|
||||
Finally
|
||||
finally
|
||||
if PreActive then
|
||||
LinkDataset.Active:=True;
|
||||
end;
|
||||
Finally
|
||||
finally
|
||||
LinkDataset.EnableControls;
|
||||
end;
|
||||
end;
|
||||
@ -115,7 +119,7 @@ procedure TFieldsListFrm.RefreshFieldsList;
|
||||
|
||||
function CheckField(f: TFieldDef): boolean;
|
||||
begin
|
||||
Result := Assigned(f) And (LinkDataSet.FindField(f.Name) = Nil);
|
||||
Result := Assigned(f) and (LinkDataSet.FindField(f.Name) = nil);
|
||||
end;
|
||||
|
||||
function FillList: integer;
|
||||
@ -124,11 +128,14 @@ procedure TFieldsListFrm.RefreshFieldsList;
|
||||
f: TFieldDef;
|
||||
begin
|
||||
Result := 0;
|
||||
with LinkDataset do begin
|
||||
for i := 0 to FieldDefs.Count - 1 do begin
|
||||
with LinkDataset do
|
||||
begin
|
||||
for i := 0 to FieldDefs.Count - 1 do
|
||||
begin
|
||||
f := FieldDefs.Items[i];
|
||||
if CheckField(f) then begin
|
||||
ListBox1.Items.AddObject(f.Name, f);
|
||||
if CheckField(f) then
|
||||
begin
|
||||
ListBox1.Items.Add(f.Name);
|
||||
inc(Result);
|
||||
end;
|
||||
end;
|
||||
@ -147,10 +154,10 @@ begin
|
||||
LinkDataset.FieldDefs.Update;
|
||||
PreActive:=LinkDataset.Active;
|
||||
LinkDataset.Active := False;
|
||||
Try
|
||||
try
|
||||
i := FillList;
|
||||
BitBtnOk.Enabled := i > 0;
|
||||
Finally
|
||||
finally
|
||||
if PreActive then
|
||||
LinkDataset.Active:=True;
|
||||
end;
|
||||
@ -161,8 +168,10 @@ constructor TFieldsListFrm.Create(AOwner: TComponent; ADataset: TDataset;
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
LinkDataset := ADataset;
|
||||
if Not Assigned(LinkDataset) then ShowMessage('LinkDataset = nil!')
|
||||
else begin
|
||||
if not Assigned(LinkDataset) then
|
||||
ShowMessage('LinkDataset = nil!')
|
||||
else
|
||||
begin
|
||||
FDesigner := ADesigner;
|
||||
Caption := fesFlTitle + ' - ' + LinkDataset.Name;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user