INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

TImage -> created dynamically

TImage -> created dynamically

(OP)
Hi,
I have problem with dynamic creation of TImage on TTabSheet. To make it, I use code below but it doesn't work - I don't see any Image on TabSheet. I don't know what I do wrong. Anybody knows?

-------------
On Form, I have PageControl where I want to create some number of TabSheet, for example 4 sheets, so my code looks like below:

procedure DoSomething;
var
NewTabSheet: TTabSheet;
NewImage: TImage;
i: Integer;
begin

for i := 0 to 3 do
begin
NewTabSheet := TTabSheet.Create(Form.PageControl);
NewTabSheet.PageControl := Form.PageControl;
NewTabSheet.Name := 'MySheet' + IntToStr(i);
NewTabSheet.Caption := IntToStr(i);

NewImage := TImage.Create(NewTabSheet);
NewImage.Parent := NewTabSheet;
NewImage.Name := 'imgMyPicture' + IntToStr(i);
NewImage.Align := alClient;
NewImage.Canvas.Font.Color := clGray;
NewImage.Canvas.TextOut(10, 10, 'Page: ' + IntToStr(i));
end;
end;

RE: TImage -> created dynamically

Set the parent of the TImage and you should be fine.

CODE

procedure TForm1.Button1Click(Sender: TObject);
// puts new MyImage on currently selected tab sheet of pagecontrol1.
begin
  if OpenDialog1.Execute then
    begin
      MyImage := TImage.Create(self);
      MyImage.Picture.LoadFromFile(OpenDialog1.FileName);
      MyImage.Parent := PageControl1.ActivePage;
    end;
end; 

If nothing is showing up, where are you getting the image data from, and are you sure it exists?

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.

RE: TImage -> created dynamically

(OP)
I don't load image from file, I use Canvas.TextOut.

If I load image from file, everything is OK but it's not what I want.

RE: TImage -> created dynamically

Hi,

Try a test with the code below:

CODE -->

procedure TForm1.Button1Click(Sender: TObject);

  procedure DoSomething;
  var
    MyPageControl: TPageControl;
    NewTabSheet: TTabSheet;
    NewImage: TImage;
    i: Integer;
  begin
    MyPageControl        := TPageControl.Create(Self);
    MyPageControl.Parent := Self;
    MyPageControl.Align  := alClient;
    for i := 0 to 3 do
    begin
      NewTabSheet := TTabSheet.Create(Self);
      NewTabSheet.PageControl := MyPageControl;
      NewTabSheet.Name := 'MySheet' + IntToStr(i);
      NewTabSheet.Caption := IntToStr(i);

      NewImage := TImage.Create(NewTabSheet);
      NewImage.Parent := NewTabSheet;
      NewImage.Name   := 'imgMyPicture' + IntToStr(i);
      //NewImage.Align  := alClient;
      NewImage.Left   := 0;
      NewImage.Top    := 0;
      NewImage.Width  := NewTabSheet.ClientWidth;
      NewImage.Height := NewTabSheet.ClientHeight;
      NewImage.Canvas.Brush.Color := clYellow;
      NewImage.Canvas.FillRect(Rect(0, 0, NewImage.Width, NewImage.Height));
      NewImage.Canvas.Font.Color  := clGray;
      NewImage.Canvas.TextOut(10, 10, 'Page: ' + IntToStr(i));
    end;
  end;

begin
  DoSomething;
end; 

Hope it's useful.

http://www.imoveisemexposicao.com.br/imobiliarias-em-guarulhos

RE: TImage -> created dynamically

(OP)
It works!!! Thank you very much smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close