Coordinates in a TScrollBox

I am writing a component that includes a TScrollBox. Into this ScrollBox I put several labels (TLabel). After inserting a Label I increase the position variables (CurrentX, CurrentY) to identify the position for the next label that may be inserted.
All this works fine if I do not scroll the client area of the ScrollBox.
If I scroll it e.g. downwards, the next label I insert will be placed incorrectly. CurrentX and CurrentY seem to be the absolute coordinates of the clientArea of the ScrollBox.
How can I convert them into logical coordinates to place the labels correctly, even if I scroll the field?
Who is Participating?
kretzschmarConnect With a Mentor Commented:
hi klusi,

what about this

  X : Integer = 10;
  Y : Integer = 10;

procedure TForm1.Button1Click(Sender: TObject);
var L : TLabel;
  L := TLabel.Create(Self);
  L.Top := Y - ScrollBox1.VertScrollBar.Position;
  L.Left := x;
  L.Caption := 'Label at '+inttostr(x)+':'+inttostr(y));
  L.Parent := ScrollBox1;
  Y := Y + l.Height + 2;  //prepare for next line

How are you getting/setting the positions?
something along the lines of
label[i].top := label[ii].top-label[ii].height;
should work where ii is last label inserted,i is new label..we did something on a question here like this adding panels to the scrollbox.
remember also you can set the labels align property to alTop
as each label is added they will be added directly below the last label.
klusiAuthor Commented:
Thank you. I tried it out and it worked perfectly.
All Courses

From novice to tech pro — start learning today.