1 (edited by gonpublic2k 2018-07-02 18:58:27)

Topic: Image replace by script

Hello all MVD fans and experts,

I need help with displaying a picture based on user input by script.  Basically I want to display a picture depending on what the user inputs on
an edit field, and using script to accomplish the task.  I'm thinking maybe, using case statements or if - then- else chains in the script, sort of
like:

procedure Form1_edit1_OnChange (Sender: TObject);
begin
if  Form1.edit1.Text = 'PHARMACY' then Form1.Picture1.Picture := ('\img\pharmacy.png') else if
   Form1.edit1.Text = 'REPAIR SHOP' then Form1.Picture1.Picture := (\img\repairshp.png');
end;
.....
....

Don't know how to write this code, just put that as an example.  Your help is greatly appreciated.  Thanks!!

2 (edited by derek 2018-07-02 21:10:47)

Re: Image replace by script

Hi There,
A couple of things to point out, if you don't mind;
1.   I think it would be better to display a picture based on a value from a combobox rather than from an edit field (if the user types in something incorrectly, for example, the picture won't show).
2.  perhaps not too relevant in your example, but hard coding it into the script means that if a new option is used (for example, a bakery) then this won't get selected unless the developer adds it into the script).
Attached is a small example of how I might approach it which 'future-proofs' you against any additions/changes to shop type;  hopefully it can give you some ideas.
Regards,
Derek.

Post's attachments

Attachment icon shop.zip 999.63 kb, 175 downloads since 2018-07-02 

Re: Image replace by script

Hello,


Just a quick explanation and answer as I'm pretty sure Derek had it all covered already.


The component in which you display some graphics is a Timage and it's content is the picture.


So in order to manually load a picture in a TImage you just need to write :

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
    Form1.Image1.Picture.LoadFromFile('.\001.jpg');
end;

Pay attention to the path to the image and the extension (I know MVD handles jpegs and pngs but for the others I don't remember).


You can of course trigger such a command on an edit field change event.


Have a good day both of you


Cheers


Math

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Image replace by script

Ok, good things pointed out.  Thanks a lot to both of you, Derek and Mathias.  As always a great help!!

Re: Image replace by script

Great Work, Thanks very help full.

Re: Image replace by script

Thanks, its help me too.

JUST LEARNING, O GOD HELP ME.