Recent

Author Topic: Whats wrong with this code  (Read 3330 times)

BSaidus

  • Sr. Member
  • ****
  • Posts: 379
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Whats wrong with this code
« on: May 18, 2021, 11:19:39 pm »
Hello.
I have a simple 2 forms, one main and the seconde is called by clicking on a menu item.
in the second form I put a TEdit .
I use this code :
Code: Pascal  [Select][+][-]
  1. procedure TfrMain.mnlstPatientsClick(Sender: TObject);
  2. begin
  3.   Form2:= TForm2.Create(Self);
  4.   Form2.Parent := Self;
  5.   Form2.Show;
  6. end;
  7.  

I want that the Form2 will be shown in the frMain .
It works but the Edit on the form can't receive focus .
Can you tel me what wrong with that and why the focus is not showed.


Thanks you.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

jamie

  • Hero Member
  • *****
  • Posts: 4570
Re: Whats wrong with this code
« Reply #1 on: May 18, 2021, 11:26:19 pm »
what is it lately with people wanting to put forms in forms?

Anyways... Use the Windows.SetParent…

windows.SetParent(Form2.Handle, Form1.Handle);

Laz has an issue with this, maybe it should be fixed one day because it works fine in Delphi//

also you need to do this each time you change the border style because laz recreates the window handle


The only true wisdom is knowing you know nothing

BSaidus

  • Sr. Member
  • ****
  • Posts: 379
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Whats wrong with this code
« Reply #2 on: May 18, 2021, 11:33:10 pm »
Thank you Jamie,
I will do that.

Quote
what is it lately with people wanting to put forms in forms?
.
I have no way to do, MDI is deprecated and not implemented well in Lazarus,
TDI is not so easy to use.
SDI is in my opinion not aesthetic ( not beautifully ) especially when using showmodal().
If you have other way, i take.

Thank you.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Handoko

  • Hero Member
  • *****
  • Posts: 4291
  • My goal: build my own game engine using Lazarus
Re: Whats wrong with this code
« Reply #3 on: May 19, 2021, 04:22:25 am »
You said forms in forms, isn't it what TFrame created for?
https://wiki.freepascal.org/Frames
« Last Edit: May 19, 2021, 04:24:44 am by Handoko »

BSaidus

  • Sr. Member
  • ****
  • Posts: 379
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Whats wrong with this code
« Reply #4 on: May 19, 2021, 02:52:49 pm »
@jamie
This approche ( you told me ) do not work well.
I use : Lazarus 2.0.10 r63526 FPC 3.2.0 i386-win32-win32/win64
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Leledumbo

  • Hero Member
  • *****
  • Posts: 8341
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Whats wrong with this code
« Reply #5 on: May 19, 2021, 11:35:32 pm »
I have no way to do, MDI is deprecated and not implemented well in Lazarus,
TDI is not so easy to use.
I think MDI is better stated as obsolete. Really no new applications are using it, even older apps are being ported away from it if not already (e.g. MS Office, Adobe Acrobat). It's either TDI or docked windows nowadays, depending on your application design.
« Last Edit: May 19, 2021, 11:39:59 pm by Leledumbo »

Blade

  • Full Member
  • ***
  • Posts: 105
Re: Whats wrong with this code
« Reply #6 on: May 20, 2021, 01:20:35 am »
what is it lately with people wanting to put forms in forms?

I think many people are searching for dynamically generated forms.  However, they are likely getting kind of stuck because the most obvious way is to use the IDE, so then you get the standard built form with dynamically generated forms from say a button.  There is also a security element to this, as if you built forms in the standard way, this can be easily seen with resource hacker.  All the .lfm data can be found there.

Completely dynamically generated forms are doable.  The more you do it, probably the more you will get used to it.  But, then you lose a lot of the features of the IDE or the person must cross reference with Object Inspector as to what features or options are available until memorized. 

Possibly a solution for this would be in converting the .lfm data, so that it would be dynamically created by the executable.  I believe there was some type of Delphi utility that did such (for their equivalent of lfm).

jamie

  • Hero Member
  • *****
  • Posts: 4570
Re: Whats wrong with this code
« Reply #7 on: May 20, 2021, 02:20:11 am »
@jamie
This approche ( you told me ) do not work well.
I use : Lazarus 2.0.10 r63526 FPC 3.2.0 i386-win32-win32/win64

I don't know what your problem is.
I can make that work with out any issues..

There is one thing you may want to change and this is how you create the child form...
Instead of doing the create for the form:
Try using
Application.CreateForm(YourChildFormClassName, Return_Instance_To_Reference);

This allows the Application class to update all the forms properly.

You still need to use the Windows.SetParent(NewChildForm.Handle, ParentForm.Handle);


I also wanted to note that the TRUNK has working MDI for windows in it.. I've tried it before and seems to work..
Maybe you should try the trunk because true MDI also inserts the MENU's of each active Child form into the main menu.


The only true wisdom is knowing you know nothing

BSaidus

  • Sr. Member
  • ****
  • Posts: 379
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Whats wrong with this code
« Reply #8 on: May 22, 2021, 08:52:24 am »
Hi,
And thanks for your responses and help.
Finally I decided to switch to TDI technic, using staff from JVCL ( JvTabBar and JvPageList )
Thank you.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

 

TinyPortal © 2005-2018