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
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
maybe you should show your code of the procedure graph
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?
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
yOff - round(yScale * (strTofloat(ListBoxB.Items
for x := 0 to ListBoxA.Items.Count -1 do
begin
output.canvas.LineTo( xOff + round(xScale * (strTofloat(ListBoxA.Items
( yOff - round(yScale * (strTofloat(ListBoxB.Items
end;
any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ;-)
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 ;-)
ASKER
right and how do you initialise them?
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
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 ;-)
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
anyway the cause of your problem is
you are working with uninitialized variables
just as fact
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?
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)
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 ;-)
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 ;-)
ASKER
AHHHHHHHHHHHHHHHHHHHHHHHHH HH
you really are a guru, i would change that to excellent if i could.
:)
you really are a guru, i would change that to excellent if i could.
:)
Grade changed to A
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange
ASKER
LOL
the guru's do know the admins well.
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 ;-)
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 ;-)
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
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?
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?
ASKER
umm nope its not the cause.
i'll put more code on
procedure TForm1.CheckBoxX2Click(Sen der: 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.
i'll put more code on
procedure TForm1.CheckBoxX2Click(Sen
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.
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(memo x.Lines);
memox.Clear; //<-- should this not be memox.lines.Clear;
memox.lines.assign(listbox X2.Items); //? error
well, going to bed now
meikl ;-)
(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(memo
memox.Clear; //<-- should this not be memox.lines.Clear;
memox.lines.assign(listbox
well, going to bed now
meikl ;-)
ASKER