mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 00:29:28 +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'
|
Caption = 'FieldsListFrm'
|
||||||
ClientHeight = 271
|
ClientHeight = 271
|
||||||
ClientWidth = 173
|
ClientWidth = 173
|
||||||
LCLVersion = '0.9.25'
|
LCLVersion = '0.9.29'
|
||||||
object BitBtnOk: TBitBtn
|
object BitBtnOk: TBitBtn
|
||||||
Left = 9
|
Left = 9
|
||||||
Height = 25
|
Height = 25
|
||||||
@ -36,12 +36,14 @@ object FieldsListFrm: TFieldsListFrm
|
|||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
object ListBox1: TListBox
|
object ListBox1: TListBox
|
||||||
|
Left = 0
|
||||||
Height = 232
|
Height = 232
|
||||||
|
Top = 0
|
||||||
Width = 173
|
Width = 173
|
||||||
Align = alTop
|
Align = alTop
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
|
ItemHeight = 0
|
||||||
MultiSelect = True
|
MultiSelect = True
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
TopIndex = -1
|
|
||||||
end
|
end
|
||||||
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
|
'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
|
+'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'
|
+'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'
|
+#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
|
+'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'
|
+'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'
|
+#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'
|
+'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'
|
+#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
|
+'Box1'#4'Left'#2#0#6'Height'#3#232#0#3'Top'#2#0#5'Width'#3#173#0#5'Align'#7#5
|
||||||
+'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#11'MultiSelect'#9#8'TabOrder'#2#2
|
+'alTop'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#10'ItemHei'
|
||||||
+#8'TopIndex'#2#255#0#0#0#14'TFieldsListFrm'#13'FieldsListFrm'#4'Left'#3'f'#1
|
+'ght'#2#0#11'MultiSelect'#9#8'TabOrder'#2#2#0#0#0
|
||||||
+#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
|
|
||||||
]);
|
]);
|
||||||
|
@ -68,6 +68,7 @@ var
|
|||||||
NewField: TField;
|
NewField: TField;
|
||||||
fModified: boolean;
|
fModified: boolean;
|
||||||
PreActive: boolean;
|
PreActive: boolean;
|
||||||
|
FieldDef: TFieldDef;
|
||||||
|
|
||||||
function CreateFieldName(Owner:TComponent;const AName:string):string;
|
function CreateFieldName(Owner:TComponent;const AName:string):string;
|
||||||
var
|
var
|
||||||
@ -92,21 +93,24 @@ begin
|
|||||||
LinkDataSet.Active := False;
|
LinkDataSet.Active := False;
|
||||||
fModified := False;
|
fModified := False;
|
||||||
for i := 0 to ListBox1.Items.Count - 1 do
|
for i := 0 to ListBox1.Items.Count - 1 do
|
||||||
|
begin
|
||||||
|
if ListBox1.Selected[i] and (LinkDataset.FindField(ListBox1.Items[i]) = nil) then
|
||||||
begin
|
begin
|
||||||
if ListBox1.Selected[i] And (LinkDataset.FindField(ListBox1.Items[i]) = Nil) then
|
FieldDef := LinkDataset.FieldDefs.Find(ListBox1.Items[i]);
|
||||||
begin
|
if FieldDef = nil then
|
||||||
NewField := TFieldDef(ListBox1.Items.Objects[i]).CreateField(LinkDataset.Owner);
|
Continue;
|
||||||
|
NewField := FieldDef.CreateField(LinkDataset.Owner);
|
||||||
NewField.Name := CreateFieldName(LinkDataset.Owner, LinkDataset.Name + NewField.FieldName);
|
NewField.Name := CreateFieldName(LinkDataset.Owner, LinkDataset.Name + NewField.FieldName);
|
||||||
FDesigner.PropertyEditorHook.PersistentAdded(NewField, True);
|
FDesigner.PropertyEditorHook.PersistentAdded(NewField, True);
|
||||||
fModified := True;
|
fModified := True;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
if fModified then FDesigner.Modified;
|
if fModified then FDesigner.Modified;
|
||||||
Finally
|
finally
|
||||||
if PreActive then
|
if PreActive then
|
||||||
LinkDataset.Active:=True;
|
LinkDataset.Active:=True;
|
||||||
end;
|
end;
|
||||||
Finally
|
finally
|
||||||
LinkDataset.EnableControls;
|
LinkDataset.EnableControls;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -115,7 +119,7 @@ procedure TFieldsListFrm.RefreshFieldsList;
|
|||||||
|
|
||||||
function CheckField(f: TFieldDef): boolean;
|
function CheckField(f: TFieldDef): boolean;
|
||||||
begin
|
begin
|
||||||
Result := Assigned(f) And (LinkDataSet.FindField(f.Name) = Nil);
|
Result := Assigned(f) and (LinkDataSet.FindField(f.Name) = nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FillList: integer;
|
function FillList: integer;
|
||||||
@ -124,11 +128,14 @@ procedure TFieldsListFrm.RefreshFieldsList;
|
|||||||
f: TFieldDef;
|
f: TFieldDef;
|
||||||
begin
|
begin
|
||||||
Result := 0;
|
Result := 0;
|
||||||
with LinkDataset do begin
|
with LinkDataset do
|
||||||
for i := 0 to FieldDefs.Count - 1 do begin
|
begin
|
||||||
|
for i := 0 to FieldDefs.Count - 1 do
|
||||||
|
begin
|
||||||
f := FieldDefs.Items[i];
|
f := FieldDefs.Items[i];
|
||||||
if CheckField(f) then begin
|
if CheckField(f) then
|
||||||
ListBox1.Items.AddObject(f.Name, f);
|
begin
|
||||||
|
ListBox1.Items.Add(f.Name);
|
||||||
inc(Result);
|
inc(Result);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -147,10 +154,10 @@ begin
|
|||||||
LinkDataset.FieldDefs.Update;
|
LinkDataset.FieldDefs.Update;
|
||||||
PreActive:=LinkDataset.Active;
|
PreActive:=LinkDataset.Active;
|
||||||
LinkDataset.Active := False;
|
LinkDataset.Active := False;
|
||||||
Try
|
try
|
||||||
i := FillList;
|
i := FillList;
|
||||||
BitBtnOk.Enabled := i > 0;
|
BitBtnOk.Enabled := i > 0;
|
||||||
Finally
|
finally
|
||||||
if PreActive then
|
if PreActive then
|
||||||
LinkDataset.Active:=True;
|
LinkDataset.Active:=True;
|
||||||
end;
|
end;
|
||||||
@ -161,8 +168,10 @@ constructor TFieldsListFrm.Create(AOwner: TComponent; ADataset: TDataset;
|
|||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
LinkDataset := ADataset;
|
LinkDataset := ADataset;
|
||||||
if Not Assigned(LinkDataset) then ShowMessage('LinkDataset = nil!')
|
if not Assigned(LinkDataset) then
|
||||||
else begin
|
ShowMessage('LinkDataset = nil!')
|
||||||
|
else
|
||||||
|
begin
|
||||||
FDesigner := ADesigner;
|
FDesigner := ADesigner;
|
||||||
Caption := fesFlTitle + ' - ' + LinkDataset.Name;
|
Caption := fesFlTitle + ' - ' + LinkDataset.Name;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user