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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
philipleighsCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.