?
Solved

Output Procedure to Tpaintbox

Posted on 2003-02-26
21
Medium Priority
?
254 Views
Last Modified: 2010-08-05
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
Comment
Question by:markio
[X]
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
  • 11
  • 9
21 Comments
 

Author Comment

by:markio
ID: 8024319
This is on Delphi 6 Personal Edition by the way.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8024336
maybe you should show your code of the procedure graph
0
 

Author Comment

by:markio
ID: 8024363
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Accepted Solution

by:
kretzschmar earned 300 total points
ID: 8024398
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
 

Author Comment

by:markio
ID: 8024416
right and how do you initialise them?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8024434
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
 

Author Comment

by:markio
ID: 8025298
right and how do you initialise them?
0
 

Author Comment

by:markio
ID: 8025312
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8025382
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8025462
btw.
anyway the cause of your problem is
you are working with uninitialized variables

just as fact
0
 

Author Comment

by:markio
ID: 8025493
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8025523
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
 

Author Comment

by:markio
ID: 8025568
AHHHHHHHHHHHHHHHHHHHHHHHHHHH
you really are a guru, i would change that to excellent if i could.
:)
0
 

Expert Comment

by:SpideyMod
ID: 8025580
Grade changed to A

SpideyMod
Community Support Moderator @Experts Exchange
0
 

Author Comment

by:markio
ID: 8025612
LOL
the guru's do know the admins well.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8025703
:-))
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
 

Author Comment

by:markio
ID: 8026508
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8026983
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
 

Author Comment

by:markio
ID: 8028342
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
 

Author Comment

by:markio
ID: 8028398
but that isn't a decent fix must be another way to save problem.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8028484
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 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