pas2js: fixed crash in designer popup menu

This commit is contained in:
mattias 2024-03-08 09:28:20 +01:00
parent cd6a0ddcc6
commit d9b2f91808

View File

@ -5,7 +5,7 @@ unit pas2jsrestcmd;
interface interface
uses uses
Classes, SysUtils, MenuIntf, propedits, DB, {IDEMsgIntf, }IDEExternToolIntf, stub.restdataset; Classes, SysUtils, MenuIntf, propedits, DB, IDEExternToolIntf, stub.restdataset;
Type Type
@ -62,19 +62,18 @@ begin
DoLog(Format(Fmt,Args)); DoLog(Format(Fmt,Args));
end; end;
function TIDEPas2JSRestCommandHandler.GetDataset: TSQLDBRestDataset; function TIDEPas2JSRestCommandHandler.GetDataset: TSQLDBRestDataset;
Var Var
ASelection : TPersistentSelectionList; ASelection : TPersistentSelectionList;
begin begin
Result:=nil;
ASelection:=TPersistentSelectionList.Create; ASelection:=TPersistentSelectionList.Create;
try try
GlobalDesignHook.GetSelection(ASelection); GlobalDesignHook.GetSelection(ASelection);
if (ASelection.Count=1) and (ASelection[0] is TSQLDBRestDataset) then if (ASelection.Count=1) and (ASelection[0] is TSQLDBRestDataset) then
Result:=ASelection[0] as TSQLDBRestDataset; Result:=TSQLDBRestDataset(ASelection[0]);
finally finally
ASelection.Free; ASelection.Free;
end; end;
@ -88,7 +87,6 @@ begin
// RegisterIDEMenuCommand(mnuCompDDSection,'ddeditfields',SMenuDatadictApply,@IDEDDC.ApplyDD,Nil,Nil); // RegisterIDEMenuCommand(mnuCompDDSection,'ddeditfields',SMenuDatadictApply,@IDEDDC.ApplyDD,Nil,Nil);
CmdShowData:=RegisterIDEMenuCommand(mnuCompRestSection,'showData',rsMenuRestShowData,@ShowData,Nil,Nil); CmdShowData:=RegisterIDEMenuCommand(mnuCompRestSection,'showData',rsMenuRestShowData,@ShowData,Nil,Nil);
CmdGetFieldDefs:=RegisterIDEMenuCommand(mnuCompRestSection,'createFieldDefs',rsMenuRestCreateFieldDefs,@CreateFieldDefs,Nil,Nil); CmdGetFieldDefs:=RegisterIDEMenuCommand(mnuCompRestSection,'createFieldDefs',rsMenuRestCreateFieldDefs,@CreateFieldDefs,Nil,Nil);
end; end;
procedure TIDEPas2JSRestCommandHandler.CheckDataset(Sender: TObject); procedure TIDEPas2JSRestCommandHandler.CheckDataset(Sender: TObject);
@ -100,7 +98,7 @@ Var
begin begin
DS:=GetDataset; DS:=GetDataset;
OK:=(DS<>Nil) and (DS.Connection<>Nil) and (DS.ResourceName<>''); OK:=(DS<>Nil) and (DS.Connection<>Nil) and (DS.ResourceName<>'');
CmdShowData.Enabled:=OK ; CmdShowData.Enabled:=OK;
CmdGetFieldDefs.Enabled:=OK and (DS.Connection.MetaDataResourceName<>''); CmdGetFieldDefs.Enabled:=OK and (DS.Connection.MetaDataResourceName<>'');
end; end;