diff --git a/lcl/forms.pp b/lcl/forms.pp index 2be5f70638..00a3554237 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -735,8 +735,12 @@ type snActiveFormChanged ); - { TScreen } +{$IFNDEF UseFCLDataModule} +{ TDataModule } + TDataModule = class; +{$ENDIF} + { TScreen } TScreen = class(TLCLComponent) private FActiveControl: TWinControl; @@ -752,6 +756,7 @@ type FFocusedForm: TCustomForm; FFonts : TStrings; FFormList: TList; + FDataModuleList: TList; FScreenHandlers: array[TScreenNotification] of TMethodList; FLastActiveControl: TWinControl; FLastActiveCustomForm: TCustomForm; @@ -766,6 +771,8 @@ type function GetCustomFormZOrderCount: Integer; function GetCustomForms(Index: Integer): TCustomForm; function GetCustomFormsZOrdered(Index: Integer): TCustomForm; + function GetDataModuleCount: Integer; + function GetDataModules(AIndex: Integer): TDataModule; function GetDesktopHeight: Integer; function GetDesktopWidth: Integer; function GetFonts : TStrings; @@ -782,6 +789,8 @@ type const Handler: TMethod; AsLast: Boolean); procedure RemoveHandler(HandlerType: TScreenNotification; const Handler: TMethod); + procedure DoAddDataModule(DataModule: TDataModule); + procedure DoRemoveDataModule(DataModule: TDataModule); protected function GetHintFont: TFont; virtual; public @@ -796,6 +805,7 @@ type function GetCurrentModalFormZIndex: Integer; function CustomFormBelongsToActiveGroup(AForm: TCustomForm): Boolean; function FindForm(const FormName: string): TCustomForm; + function FindDataModule(const DataModuleName: string): TDataModule; procedure UpdateScreen; // handler procedure AddHandlerFormAdded(OnFormAdded: TScreenFormEvent; @@ -831,6 +841,9 @@ type property FocusedForm: TCustomForm read FFocusedForm; property FormCount: Integer read GetFormCount; property Forms[Index: Integer]: TForm read GetForms; + property DataModuleCount: Integer read GetDataModuleCount; + property DataModules[Index: Integer]: TDataModule read GetDataModules; + property Fonts : TStrings read GetFonts; property Height : Integer read Getheight; property HintFont : TFont read GetHintFont; @@ -1277,7 +1290,7 @@ type {$IFNDEF UseFCLDataModule} -type +//type { TDataModule } TDataModule = class(TComponent) diff --git a/lcl/include/application.inc b/lcl/include/application.inc index 8a0aee4908..655a648d08 100644 --- a/lcl/include/application.inc +++ b/lcl/include/application.inc @@ -28,11 +28,15 @@ const function FindApplicationComponent(const ComponentName: string): TComponent; begin - if Application.FindGlobalComponentEnabled then begin + if Application.FindGlobalComponentEnabled then + begin Result:=Application.FindComponent(ComponentName); if Result=nil then Result:=Screen.FindForm(ComponentName); - end else + if Result=nil then + Result:=Screen.FindDataModule(ComponentName); + end + else Result:=nil; //debugln('FindApplicationComponent ComponentName="',ComponentName,'" Result=',DbgSName(Result)); end; diff --git a/lcl/include/screen.inc b/lcl/include/screen.inc index 5e50a78d9d..cefacdcc4d 100644 --- a/lcl/include/screen.inc +++ b/lcl/include/screen.inc @@ -34,8 +34,12 @@ begin FCustomForms:=TList.Create; FCustomFormsZOrdered:=TList.Create; FFormList := TList.Create; + FDataModuleList := TList.Create; FPixelsPerInch:= ScreenInfo.PixelsPerInchX; FSaveFocusedList := TList.Create; + + AddDataModule:=@DoAddDataModule; + RemoveDataModule:=@DoRemoveDataModule; end; {------------------------------------------------------------------------------ @@ -52,6 +56,7 @@ begin for HandlerType:=Low(FScreenHandlers) to High(FScreenHandlers) do FreeThenNil(FScreenHandlers[HandlerType]); FreeThenNil(FHintFont); + FreeThenNil(FDataModuleList); FreeThenNil(FFormList); FreeThenNil(FCustomForms); FreeThenNil(FCustomFormsZOrdered); @@ -166,6 +171,19 @@ begin Result:=nil; end; +function TScreen.FindDataModule(const DataModuleName: string): TDataModule; +var + i: Integer; +begin + for i:=0 to FDataModuleList.Count-1 do + if CompareText(TDataModule(FDataModuleList[i]).Name, DataModuleName)=0 then + begin + Result:=TDataModule(FDataModuleList[i]); + Exit; + end; + Result:=nil; +end; + procedure TScreen.UpdateScreen; var DC: HDC; @@ -358,6 +376,16 @@ begin Result := TCustomForm(FCustomFormsZOrdered[Index]); end; +function TScreen.GetDataModuleCount: Integer; +begin + Result:=FDataModuleList.Count; +end; + +function TScreen.GetDataModules(AIndex: Integer): TDataModule; +begin + Result := TDataModule(FDataModuleList.Items[AIndex]); +end; + function TScreen.GetDesktopHeight: Integer; begin Result := GetSystemMetrics(SM_CYVIRTUALSCREEN); @@ -571,4 +599,14 @@ begin FScreenHandlers[HandlerType].Remove(Handler); end; +procedure TScreen.DoAddDataModule(DataModule: TDataModule); +begin + FDataModuleList.Add(DataModule); +end; + +procedure TScreen.DoRemoveDataModule(DataModule: TDataModule); +begin + FDataModuleList.Remove(DataModule); +end; + // included by forms.pp