Link to home
Start Free TrialLog in
Avatar of markio
markio

asked on

Output Procedure to Tpaintbox

i have declared this..
procedure graph(a:Tlistbox; b:Tlistbox; output:Tpaintbox);

the code doesn't crash but the graph isn't outputted to the Tpaintbox's canvas.
I thought about maybe using a function but how would i output the results to the Tpaitnbox.
the reason for doing this is because i want to make the procedure usable so that i can use more than two list boxes for input data.

Regards
Mark
Avatar of markio
markio

ASKER

This is on Delphi 6 Personal Edition by the way.
Avatar of kretzschmar
maybe you should show your code of the procedure graph
Avatar of markio

ASKER

ok
here would be the code.

procedure Tform1.graph(ListBoxA : Tlistbox ; ListboxB : Tlistbox; output : Tpaintbox);
var x,y,xoff,yoff : integer;
    xscale, yscale : Real;
begin

  output.Canvas.pen.Width := 2;

  x := 0;
  y := 0;

  output.canvas.MoveTo(xOff + round(xScale * (strTofloat(ListBoxA.Items[x]))),
                          yOff - round(yScale * (strTofloat(ListBoxB.Items[x]))));


  for x := 0 to ListBoxA.Items.Count -1  do
  begin

    output.canvas.LineTo( xOff + round(xScale * (strTofloat(ListBoxA.Items[x]))),
                           ( yOff -  round(yScale * (strTofloat(ListBoxB.Items[x])))));



  end;

any ideas?
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of markio

ASKER

right and how do you initialise them?
depending for what they stand

try frist to init

xOff with 0
and
yOff with output.canvas.height
(guessing this is for some offset from the border
for a coordination system)

and
xScale,yScale with 1
(guessing this is for a like zoom option)

meikl ;-)
Avatar of markio

ASKER

right and how do you initialise them?
Avatar of markio

ASKER

sorry wrong button when refreshing
lol
yeah the variables are declared as public global variables and i think certain procedures are making their own private copies of these public variables instead of just updating the public global ones.

thanks for the help anyway

Mark
just to ask why a c-grade?

and local variables didn't copy anything to global
varibales, they are independent and used if they are local
defined, also if similar variables with same name are
defined global.

meikl ;-)
btw.
anyway the cause of your problem is
you are working with uninitialized variables

just as fact
Avatar of markio

ASKER

yeah, but you can't define the global variables, unless you define them locally cos it wouldn't let me.
You have given me pointers to solve the problem, which is good.
thanks for the help anyway!
how would i re-define the global variables?

like yscale,xscale has to be available in outher parts and also is changed by another procedure.
procedure Tform1.eoff(min : Tedit; output : Tpaintbox; scale : Integer; off : integer);
begin
  if min.text = '' then
  begin
  end
  else
  if (min.text = '-') then
  begin
  end
  else
  if (isInteger(min.text)) then
  begin
    off := round(StrtoFloat(min.text)* -scale);
  end
  else
  begin
    error('Invalid numerical input' );
    min.text := '-10'
  end;


end;

i send data to it using
  eoff(editXmin, paintbox1,xs,xoff);
  eoff(editYmin, paintbox1,ys,yoff);

xoff ,yoff are global variables.
would this change there values?


no,

you must define your procedure header in this way
to get it changed/returned:

procedure Tform1.eoff(min : Tedit; output : Tpaintbox; scale : Integer; var off : integer);  //<-- notice the var keyword

meikl ;-)
Avatar of markio

ASKER

AHHHHHHHHHHHHHHHHHHHHHHHHHHH
you really are a guru, i would change that to excellent if i could.
:)
Grade changed to A

SpideyMod
Community Support Moderator @Experts Exchange
Avatar of markio

ASKER

LOL
the guru's do know the admins well.
:-))
well, glad you got it.
next time before giving a c,
just reask or explain why you
want to give a c-grade afterwards.

most experts dislikes c-grades,
including me too, thats why i asked
at community support for
reviewing the grading

>i would change that to excellent if i could.
i guess you do then confirm the grade-change,
which was performed by SpideyMod
(thanks SpideyMod for doing so)

good luck again

meikl ;-)
Avatar of markio

ASKER

erm
i keep seeming to get this error
rasied Exception class EStringListError with message
list index out of bounds(1)
but its coming from

memox.lines := listboxx.items;
which works in other parts of my program
what am i doing wrong?
Mark
missing the context, where does this happen

the error caused allways if you will access a value
with an higher index than the count-1 is

btw. the lines/items are zerobased
->the first line/item has the index 0

may this the cause?
Avatar of markio

ASKER

umm nope its not the cause.
i'll put more code on

procedure TForm1.CheckBoxX2Click(Sender: TObject);
begin
 if checkboxX2.Checked = true then
 begin
   checkboxX1.Checked := false;

   listboxX.Items.Clear;
   listboxX.Items := memox.Lines;
   memox.Clear;
   memox.lines := listboxX2.Items;  // Error
 end;

 if checkboxX2.Checked = false then
 begin
   checkboxX1.Checked := true;

 end;

end;

when i have more than 1 value in the listbox and try to reload it out of the listbox into the memo it crashes with that error if there is only one value then it doesn't.
any ideas?
i can fix it by saving the contents to a fiel and loading it from the file.
Avatar of markio

ASKER

but that isn't a decent fix must be another way to save problem.
maybe assign is better method for doing
(even i have tested there would be no difference
in my testcase, but maybe in your case),
and its recommended for doing so

listboxX.Items.Clear;
listboxX.Items.assign(memox.Lines);
memox.Clear;  //<-- should this not be memox.lines.Clear;  
memox.lines.assign(listboxX2.Items); //? error

well, going to bed now

meikl ;-)