Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Error in ListView Columns

Posted on 1998-07-26
3
146 Views
Last Modified: 2010-04-04
I Create a Component as follows:

-------
type
  TMyListView = class(TCustomListView)
...

constructor TMyListView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ViewStyle:=vsReport;
  With Columns.Add do Caption:='AAA';
end;
------

But when I try to put this component on a form (in design) I get an error: 'Control '' doesn't have a parent window'
This happens on the line:   With Columns.Add do Caption:='AAA';
Any ideas?
0
Comment
Question by:ronit051397
  • 2
3 Comments
 
LVL 2

Expert Comment

by:freter
ID: 1358719
Right. This error occurs due to the fact that at the moment of executing the line "with columns.add do caption := 'AAA'; ", windows hasn't created the handle for your control yet. I experienced this behaviour myself quite often in my early days ;-)
Here's how to avoid it:
>>>>>>>>>
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, comctrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TMyListView = class(TCustomListView)
  private
    procedure CreateWnd; override;
  public
    constructor Create(AOwner: TComponent); override;
  end;
var
  Form1: TForm1;

implementation

{$R *.DFM}



constructor TMyListView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ViewStyle:=vsReport;
end;

procedure TMyListView.CreateWnd;
begin
  inherited;
  With Columns.Add do Caption:='AAA';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TMyListView.Create(self) do begin
    parent := self;
    left := 10;
    top := 10;
    visible := true;
  end;
end;

end.

<<<<<<<<<<<<<<<<<<
Don't forget to place a button named Button1 on your form an assign the event Button1CLick to it's click event.

Regards,
Freter

0
 
LVL 5

Author Comment

by:ronit051397
ID: 1358720
Many thanks,
If you post an answer I'll grade it.

Ronit,
0
 
LVL 2

Accepted Solution

by:
freter earned 50 total points
ID: 1358721
Hi Ronit!
I hope it helped you. Here is the answer to grade.

Keep smiling ;-)
Freter
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 115
Using idhttp to login to instagram 2 106
Delphi: ForceDirectory plain function 7 42
DBCtrlGrid, Delphi, Scroll 7 24
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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.

790 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