What's wrong with this code?

Hi all,

This procedure is working fine...

procedure TKarteForma.KojaSlika;
var
   Marker : TBitmap;
begin
     Marker:=TBitmap.Create;
     Marker.LoadFromResourceName(DLLHandel, Slika);
     With KarteForma.Image1.Canvas do
     begin
          Create;
          Draw(Lijevo, Gore, Marker);
          Refresh;
     end;
     Marker.FreeImage;
     Marker.Destroy;
end;
... but if i call it like this:
Slika:=Ini.ReadString('KALIBRACIJSKE TOCKE', 'Prva Slika', '');
     Lijevo:=y01;
     Gore:=x01;
     KojaSlika;
and then again          
     Slika:=Ini.ReadString('KALIBRACIJSKE TOCKE', 'Druga Slika', '');
     Lijevo:=y0;
     Gore:=x0;
     KojaSlika;
it will kill my application...
THE INTERESTING part is if i place a ShowMessage(''); between those two cals to procedure "KojaSlika" it will work fine ????
what am i missing?
Thanks
Robert
LVL 1
rpetruniAsked:
Who is Participating?
 
philipleighsConnect With a Mentor Commented:
I think that Create doesn't need to be there, and Refresh is probably not necessary either.

Try removing those two lines.

     With KarteForma.Image1.Canvas do
     begin
          Draw(Lijevo, Gore, Marker);
     end;

Cheers,
Phil.

0
 
intheCommented:
could be like a time thing try putting application.processmessages in there
and/or sleep(200)
give the app more time to load and read the images marker from dll..
0
 
simonetCommented:
Instead of putting a ShowMessage between the calls, try this:

for i := 0 to 500 do
   application.processmessages;

place the loop above between the two calls.

I would also change the KojaSlika procedure to this:

procedure TKarteForma.KojaSlika;
var
   Marker : TBitmap;
begin
   Marker:=TBitmap.Create;
   try
     Marker.LoadFromResourceName(DLLHandel, Slika);
     With KarteForma.Image1.Canvas do
     begin
        Create;
        Draw(Lijevo, Gore, Marker);
        Refresh;
     end;
     Marker.FreeImage; // Not really necessary
   finally
     Marker.free;  // Use FREE instead of Destroy.
   end;
end;

yours,

Alex
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
simonetCommented:
Well noticed, Phil :)
0
 
philipleighsCommented:
And one other thing,

Replace

     Marker.FreeImage;
     Marker.Destroy;

with

     Marker.Free;

Cheers,
Phil.
0
 
simonetCommented:
Hmmm.. that one has alredy been pinpo.inted!
0
 
philipleighsCommented:
Oh, whoops so it has. Sorry Alex, I didn't see that!

BTW, what is pinpo.inted?

Cheers,
Phil.
0
 
RBertoraCommented:
one word : PinPointed. ie figured out.
Rob;-)
0
 
philipleighsCommented:
DOH! Way to make me feel dumb Rob!!!  :-)

I'm crawling under my desk now, I'll be staying there for a while if anyone wants me!

Cheers,
Ph.il (don't ask, hehe)
0
 
RBertoraCommented:
:-( Sorry phil, I'm sure you get the next few, besides I can slip up just as much as any one else...
D.OH!
Rob;-)
0
 
rpetruniAuthor Commented:
ok, since this answer was solution (without some time loops), i'll give you points
Robert
0
 
philipleighsCommented:
Oh thanks for the points Robert!

Cheers,
Phil.
0
 
RBertoraCommented:
See who crawled out from under the table

:-)

to collect some points, not so silly after all!

Rob;-)
0
All Courses

From novice to tech pro — start learning today.