• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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
0
markio
Asked:
markio
  • 11
  • 9
1 Solution
 
markioAuthor Commented:
This is on Delphi 6 Personal Edition by the way.
0
 
kretzschmarCommented:
maybe you should show your code of the procedure graph
0
 
markioAuthor Commented:
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?
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
kretzschmarCommented:
hmm,

maybe you paint outside the visible view of your paintbox,
usual it should work

in your code sample i miss some inits
(xOff, yOff, xScale, yScale)

if you do not init this values,
then they are randomly and the chance that
you paint somewhere instead of the visible view
is very high

meikl ;-)
0
 
markioAuthor Commented:
right and how do you initialise them?
0
 
kretzschmarCommented:
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 ;-)
0
 
markioAuthor Commented:
right and how do you initialise them?
0
 
markioAuthor Commented:
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
0
 
kretzschmarCommented:
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 ;-)
0
 
kretzschmarCommented:
btw.
anyway the cause of your problem is
you are working with uninitialized variables

just as fact
0
 
markioAuthor Commented:
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?


0
 
kretzschmarCommented:
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 ;-)
0
 
markioAuthor Commented:
AHHHHHHHHHHHHHHHHHHHHHHHHHHH
you really are a guru, i would change that to excellent if i could.
:)
0
 
SpideyModCommented:
Grade changed to A

SpideyMod
Community Support Moderator @Experts Exchange
0
 
markioAuthor Commented:
LOL
the guru's do know the admins well.
0
 
kretzschmarCommented:
:-))
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 ;-)
0
 
markioAuthor Commented:
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
0
 
kretzschmarCommented:
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?
0
 
markioAuthor Commented:
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.
0
 
markioAuthor Commented:
but that isn't a decent fix must be another way to save problem.
0
 
kretzschmarCommented:
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 ;-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 11
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now