Forum > Designer
How to insert a form in a unit and have the IDE manage it?
Sieben:
Maybe you're looking for sth like this - from my own version but essentially code from unit Dialogs. Creating a TForm code only:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type { TaxInputForm } TaxInputForm = class(TForm) private Edit: TCustomEdit; FNonChars: TCharSet; procedure InputEditChange(Sender: TObject); procedure InputEditKeyPress(Sender: TObject; var Key: Char); protected procedure Activate; override; end; // + the implementations function axCreateInputDialog(OwnerForm: TCustomForm; const ACaption, APrompt: string; MaskInput: Boolean; NonChars: TCharSet; const AMask: string; AEditClass: TEditClass; var Value: string): TaxInputForm;var Prompt: TLabel; MinEditWidth: integer; AMonitor: TMonitor;begin Result := nil; Result := TaxInputForm(TaxInputForm.NewInstance); Result.DisableAutoSizing; Result.CreateNew(OwnerForm); with Result do begin FNonChars := NonChars; PopupMode := pmAuto; BorderStyle := bsDialog; Caption := ACaption; Prompt := TLabel.Create(Result); with Prompt do begin Parent := Result; Caption := APrompt; Align := alTop; AutoSize := True; end; Edit := AEditClass.Create(Result); with Edit do begin Parent := Result; Top := Prompt.Height; Align := alTop; BorderSpacing.Top := 3; AMonitor := _InputQueryActiveMonitor; // check that edit is smaller than our monitor, it must be smaller at least // by 6 * 2 pixels (spacing from window borders) + window border MinEditWidth := Min(AMonitor.Width - 20, Max(cInputQueryEditSizePixels, AMonitor.Width * cInputQueryEditSizePercents div 100)); Constraints.MinWidth := MinEditWidth; OnKeyPress := @Result.InputEditKeyPress; OnChange := @Result.InputEditChange; {$ifdef with_picedits} if (AEditClass = TPxPicEdit) then TPxPicEdit(Edit).ValueConstraints.PictureMask := AMask; {$endif} if (AEditClass = TMaskEdit) then TMaskEdit(Edit).EditMask := AMask; if (Value > '') then Text := Value; TabStop := True; if MaskInput then begin EchoMode := emPassword; PasswordChar := '*'; end else begin EchoMode := emNormal; PasswordChar := #0; end; TabOrder := 0; end; with TaxDlgBtnPnl.Create(Result) do begin Top := Edit.Top + Edit.Height; Parent := Result; ShowBevel := False; ShowButtons := [pbOK, pbCancel]; Align := alTop; end; ChildSizing.TopBottomSpacing := 6; ChildSizing.LeftRightSpacing := 6; AutoSize := True; InputEditChange(Edit); // upon show, the edit control will be focused for editing, because it's // the first in the tab order Result.EnableAutoSizing; end;end;
IDE/OI, however, will of course not manage this.
LV:
--- Quote from: jamie on October 15, 2024, 09:57:39 pm ---
I have question about later deciding to insert a Form in a UNIT that got started without any interacting with the IDE designer.
Is it possible to insert a form class into an existing unit and have it be managed by the IDE/OI ?
I don't mean in forms of editing the LFM file, is there an option to start a new form within an existing unit?
--- End quote ---
The answer is yes if the conditions are met:
1) the *.lfm file must be created, otherwise the Object Inspector will not see the form;
2) You need to add a line to the *.lpr (Application.CreateForm(...););
I spent 3 mins checking it out.
--- Quote from: MarkMLl on October 15, 2024, 10:22:39 pm ---What happens if you add the relevant .pas file to the project?
I admit to being somewhat uncomfortable with this distinction between "form" and "unit", which is something that I've seen people making repeatedly (https://forum.lazarus.freepascal.org/index.php/topic,65825.0.html and so on). The important thing is the unit and the class (descendant of TForm) defined therein in the context of Object Pascal: the IDE should take note of the presence of that and (a) compile the associated .lfm into a collection of resources and (b) use those resources to populate a form at program startup.
MarkMLl
--- End quote ---
I'm of the same opinion. I will add a discussion close to this issue
https://forum.lazarus.freepascal.org/index.php/topic,68574.0.html
Navigation
[0] Message Index
[*] Previous page