Solved

MDI-parent caption

Posted on 1998-06-22
7
610 Views
Last Modified: 2010-04-04
How do I get caption on and MDI-child's parent window?

I've tried
TForm(myForm.Parent).Caption
but TForm(myForm.Parent) returns nil. Why?
SHouldn't a MDI-childs parent be set to the hWnd of it's MDI-parent???
0
Comment
Question by:dr_gonzo
7 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 1354999
TForm(myForm.Owner).Caption

Regards Jacco
0
 

Expert Comment

by:buboi
ID: 1355000
MyForm.Parent returns a Twincontrol, it does not include the information about Caption. So you cast it to TForm, this TForm.Caption is nil, it's normal.

if you want to get the mainform's caption, you needn't use Parent property. In your child form unit, you add a uses clause
to allow you directly use mainform. for example:
mainform unit name:main.pas
var
   mainform:TMainForm;
.

in your child form unit file:

.
implementation
uses main;
.

// str:=TForm(MyForm.Parent).Caption;
// change to:
   str:=mainform.caption;
.

Everything will ok!





0
 

Author Comment

by:dr_gonzo
ID: 1355001
To Jaccu:
Nop same problem the caption is by Delphi said to be ''. Read buboi's comment to see why.

To Buboi:
That's what I would have done, but I'm writing a component which need's eighter the owner's caption (if it is a non-MDI) or the owner's parent (if it is MDI) so it is impossible to use USES in this case, any other clues?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:dr_gonzo
ID: 1355002
Hmm by the way. If it was a cast-problem why don't this work:

Self.Parent

It also returns nil.
Is the property I'm looking for owner?????
I'm getting more and more confused. I thought I knew Delphi quite well.
0
 
LVL 4

Accepted Solution

by:
d003303 earned 30 total points
ID: 1355003
Yo,
use this:

function TForm1.GetMDIParentCaption: string;
var
  AHandle : THandle;
  Buf     : array[0..255] of Char;
begin
  AHandle := Self.Handle;
  while Windows.GetParent(AHandle) <> 0
   do AHandle := Windows.GetParent(AHandle);
  // now AHandle is the top parent window
  GetWindowText(AHandle, Buf, 255);
  Result := String(Buf);
end;

Slash/d003303
0
 

Author Comment

by:dr_gonzo
ID: 1355004
Yepp!
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1355005
Two other options:

1)
Application.MainForm.Caption := 'My new caption'

2)
for iForm:=0 to Screen.FormCount-1 do
  for iChild:=0 to Screen.Forms[iForm].MDIChildCount-1 do
    if Screen.Forms[iForm].MDIChildren[iChild]=Self then
      Screen.Forms[iForm].Caption:='Hallo';

Regards Jacco
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Communication Between RC4 Delphi <-> PHP 3 123
Help on project with Soap 10 57
Delphi XE10 Round Image 2 160
Delphi: barcode reading on android platform 1 51
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question