Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

ComboBox Select item - Selects URL

Hello All;

  let me clearify the Subject line here a little better.

Lets say the following exist:

ComboBox.Items

USA
Canada
UK

Now. I need to associate each of these items in the ComboBox with a specific URL.
(These are examples only, I wonder if they all exist, they should)
USA = usa.com
Canada = canada.com
UK = uk.com

I need the ComboBox.Item.Selected
To be inserted into a IniFile (This is not a problem, easy as pie to do)
BUT.. This is the kicker here.
I DO NOT want the URL's to be listed in the IniFile. As in: I do not want the End User to be able to Edit
The IniFile and change it's contents.

I have each of the URL's listed in TEdit's that will be on a TabSheet.Visible := False;
This way the End-User will not be able to see, nor be able to edit these set values.

OK.
Now when the User Selectes the [Country] from the TComboBox.
I need to have the information from the TEdit.
USAEdit = usa.com
CanadaEdit = canada.com
UKEdit = uk.com

To be placed in this

procedure TForm1.ShowPage;
ShellExecute(0, 'open',
                   PChar(''+ Selected Country URL goes here +''),
                   nil, nil, SW_SHOWMAXIMIZED);
End;

Any idea's on how to do this?
I have been searching through EE, and found some information but nothing pertaining to
What I am after.
And Google, is a pain sometimes to find the right information.
To much split of words to find what you need.
Starting to become an aggrivating dealing with Google's search engine.

Thanks All;
Carrzkiss
SOLUTION
Avatar of CodedK
CodedK
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wayne Barron

ASKER

Hey guys.
Just thinking of something here.

I did a test.

1 ComboBox (With Countries)
Edit1.text; = With URL
Edit2.text; = Copies from the Edit1

If I can somehow know which "Edit" Is selected by the ComboBox.Items (Country)
Then I can have it do something like this

procedure TForm1.ShowPage;
ShellExecute(0, 'open',
                   PChar(''+ edit2.text +''),
                   nil, nil, SW_SHOWMAXIMIZED);
End;

This way it will get the information from the 2nd TEdit. and list it in the URL.

I will post more as I play around with it.

Take Care All;
Sorry didnt read ur question :/
Hello CodedK;

  Yes I know that information.
But the URL is not hard coded into the ShellExecute.
It is as you can see in the original post, and in the example above here.
It is located in a String.
But I need to find a way to make it work like I have indicated above.

Any other suggestions?
No :)
Sorry i thought that this was one of the answer-quick easy questions...
:)
Still trying to read the whole question lol...
Unfortunantly, This is not one of them.
Then again, there is probably someone that will jump in here.
And through it out.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thats what i understood too. :/
Or do you want to encrypt the ini file?
Something like this:

CountryComboBoxOnChange;

CountryCombo.Items.Strings[CountryCombo.ItemIndex];
Edit3.Text := Edit1.Text;


But if I have
Edit1.text := USA.com
Edit2.text := Canada.com

Edit3.text := Takes the information from either of the Edit1 (or) Edit2.
Depending on which Country is selected from the CountryCombo.

But this is not working?
Avatar of shaneholmes
shaneholmes

Yup - I'm definately reading your question right -

"Now when the User Selectes the [Country] from the TComboBox.
I need to have the information from the TEdit.
USAEdit = usa.com
CanadaEdit = canada.com
UKEdit = uk.com

To be placed in this

procedure TForm1.ShowPage;
ShellExecute(0, 'open',
                   PChar(''+ Selected Country URL goes here +''),
                   nil, nil, SW_SHOWMAXIMIZED);
End;

Any idea's on how to do this"

Comment from CodedK

>>>>Sorry didnt read ur question :/

Sometimes it does help to read the question, so that you will know exactly what the
Person is needing. The Subject line does not always tell the full story.

Thanks anyway
I don't beieve your Description tells the full story neither - What you are asking for is what i just gave you above (in code) , but something tells me your asking for more - so if that is the case, you will need to clarify your question better....

sholmes
Hello Shane;

  Basically yes.

  Except I do not want the item to launch the Web Page, when the ComboBox is Selected.
Instead, I need it to:

Save the current Selected ComboBox "Country" into an IniFile (Which I have done already)
That will have the Selected "Country Edit.text := ''''' set;
And when the program is run, It will automatically have the Selected country setting (''+URL+'') underneath the
Code:

procedure TForm1.ShowPage;
// ShowPage; is a Button. When the user clicks on the Button.
// The page will load
// For this demostration, I will just use the Button1Click
procedure TForm1.Button1Click;
ShellExecute(0, 'open',
                   PChar(''+ edit2.text +''),
                   nil, nil, SW_SHOWMAXIMIZED);
End;



I hope I explained it properly
Well, if you done it already - what are you asking of us?

You are not clearly stating your question - please don't use the term "underneath the code" your confusing us....


sholmes
Going back over all your descriptions here - wHen i read any of them, i get very confused....

That will have the Selected "Country Edit.text := ''''' set;   ?????????????????????????????


he Selected country setting (''+URL+'') underneath theCode: ????????????????????????????



// ShowPage; is a Button. When the user clicks on the Button.

Showpage is not a button, it is a procedure called from a button's OnClick event i presume

WOW - not im getting even more confused - <SMILE>

k - i gotta move on to bigger and better things - good luck guys!

sholmes
OK. Lets try this again:

Form sets like so:

1 - ComboBox ( Countries listed: USA, Canada, UK )
3 - TEdits
Edit1.text := usa.com
Edit2.text := canada.com
Edit3.text := uk.com

edit4.text

procedure TForm1.Button1Click;
ShellExecute(0, 'open',
                   PChar(''+ edit4.text +''),
                   nil, nil, SW_SHOWMAXIMIZED);
End;

------------------------------------------------------------
Now.
Shane, you are close to what I am needing. But not quite.

When you select from the ComboBox, your Country.
This is what needs to happen.

ComboBox.OnChange [USA]
edit1.Text := usa.com  <-  Is selected
edit4.text := usa.com <-- Edit1.text is Copied over to Edit4.text
Last: edit4.text is displayed here:  PChar(''+ edit4.text +''),

Now. The ComboBox will be saved to an IniFile. For the Country that is selected.
When the program is run, the Selected Country will appear only in the Form
Of the   PChar(''+ edit4.text +''),

As the Selected Country (ComboBox) Is already set. Which has its Focus set on
Its particular Country URL (edit.text := url.com)


Does this explain it to you better?
If not, then I will try again.

:-)
Now that you have written it out like that, I am confused too ;-)

That is bad! Getting confused on your own writtings.

That is what you get, when you try to write out how you need something done.
When someone is asking you questions at the same time.
And in my case, I am trying to answer the question being asked.
And trying to type at the same time.

Sorry guys
Ok Ive been following this conversation, but even Im still slightly confused lol

What I dont understand it what you need edit1, edit2 and edit3 for if edit4 is being used along with a combo box.
Seems like you basically trying to use an ini file for form settings, but this seems a bit of a round about way to do it.
>When the program is run, the Selected Country will appear only in the Form Of the   PChar(''+ edit4.text +'')<

Dont you just need to read your ini file on application load to check for any pre-determined options, and populate your components if something exists or not.
Your basically hardcoding a relationship between a country and a url, couldnt this be achieved with the same results just within the application?
I follow up to this point:

When you select from the ComboBox, your Country.
This is what needs to happen.

ComboBox.OnChange [USA]
edit1.Text := usa.com  <-  Is selected
edit4.text := usa.com <-- Edit1.text is Copied over to Edit4.text


Then you loose me on this:

Last: edit4.text is displayed here:  PChar(''+ edit4.text +''),

What are the 2 +'s for?


Im lost here:

Selected Country will appear only in the Form
Of the   PChar(''+ edit4.text +''),


and I'm lost here:


As the Selected Country (ComboBox) Is already set. Which has its Focus set on
Its particular Country URL (edit.text := url.com)



THINK - then describe carefully exactly what you want:

Use lots of space t describe - cause in the long wrong, look at all the space we are using anyways - and we are getting no wheres

sholmes

I need to keep the URL's that are located in the TEdit's out of prying eyes of the end-uers.

If you have a better way of doing it, then by all means, please assist.

The information that i have provided is from what I have tried.
And so far what I have tried does not work.
So if either of you have a better way of achiving this then please, by all means.

Though my method may seem a little unorthodox, it is the only thing that I could come up with.
But as always, I am open to suggestions and code changes.

The only thing that I ask, is that the URL's are not visible to the End-User.
(Not implanted into an inifile)
And that the ending URL That is selected is under the Button with the  PChar(''+ edit4.text +'')<
And that the same country that the user selected, is shown "Everytime" the program is runned.

So by all means, Feel free to give me what ever you can thank of.
How about encoded and stored in the Registry?

sholmes
Alright, Im working on a sample for you.

sholmes
If the URL's can be some how encrypted to where they cannot by no means
Be revealed in the Regisrty (Reverse Engenering) the yes.
They can be stored in the Registry.

See the URL's hold very vital information in them.
And if the End-User was able to edit these URL's then
They could really mess the whole thing up.

But if you can provide a way of making them "Non Edited Registry Entries"
Then please by all means, Go for it.

By the way.

ShellExecute(0, 'open',
                   PChar(''+ edit4.text +''),
                   nil, nil, SW_SHOWMAXIMIZED);

The 2 +'s have to be there.
This grabs the URL example: of a working url

('http://www.some.com/something/'+edit1.text+''),

See without the URL in place it would be

(''+edit1.text+'')
But the +'s have to be there, or it will not work, nor will it compile.

As for explaining for.
I understand what I last wrote.
It is self explained.
But if you want me to better describe. I doubt I can, as that is as simple as it gets
At least on my end.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is the registry unit

unit UntReg;

interface

uses Forms, Windows, Registry, Classes, SysUtils, Dialogs;


procedure ReadRegistry;
procedure WriteRegistry;

var
 USAUrl, UKUrl, CANUrl: String;

implementation


procedure WriteRegistry;
var
 Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\Test\Countrys\', True) then
    begin
     Reg.WriteString('USA Url', USAUrl);
     Reg.WriteString('UK Url', UKUrl);
     Reg.WriteString('CAN Url', CANUrl);
     Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;

procedure ReadRegistry;
var
 Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\Test\Countrys\', True) then
    begin
     if Reg.ValueExists('USA Url') then
      USAUrl:= Reg.ReadString('USA Url');
     if Reg.ValueExists('UK Url') then
      UKUrl:=  Reg.ReadString('UK Url');
     if Reg.ValueExists('CAN Url') then
      CANUrl:=  Reg.ReadString('CAN Url');
     Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;


initialization
 ReadRegistry;
finalization
 WriteRegistry;
end.
Let me know if you want me to email you the application (zipped up) - its small

I would need your email

sholmes
Oops I forgot this part!

procedure TForm1.Button1Click(Sender: TObject);
begin
 ShellExecute(Application.Handle,PChar('open'),PChar(edit4.Text),PChar(''),nil,SW_NORMAL);
end;
If these URLs are hardcoded to a country selected in the combobox wouldnt it just be as easy to store the values somewhere in the application?
I got it to work. But I just ran into a problem that has me a little stumped right now.

The URL's that are in the "Edit's.text" Are like so:
Example:
https://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_'+Search.text+'.html

Where the
Search.text will be where you would (in this case) add in the Q_#######
To bring the page up.

Unfortunantly, It is not working as I had planned.
As with the Edit4.text which gets its information from the ComboBox.
Which added its information into the PChar(edit4.text)
It is not allowing me to add anything else to it.

Also, the Registry, anyway to make it Encrypted? To where it is non-readable?
That is a BIG thing in the project as explained above. It cannot be readable.
If it is Readable then it will be found, and can be edited
Here you go.
This way you will better understand what is going on

http://www.carrz-fox-fire.com/1/Q_21377601.zip
mikelittlewood;

  If you have a better solution, I am open to what ever I can get.
Please by all means, the more envolved the better chance of getting
This one done.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Whay don' crypt the ini dates? And decrypt when need to use it.
Hello Ginsonic;

   Can you supply a sample code of "Encrypting and Decrypting" that IniFile?
As mentioned above, I am open to an and all suggestions in this project.

Thanks
Did you not like my example?

sholmes
Hello Shane;

  Yes I liked the example that you provided.

Did you have an opertunity to take a look at the example
And the issue that I am up against?
http://www.carrz-fox-fire.com/1/Q_21377601.zip

Where the links are like this:
https://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_'+Search.text+'.html

If I can get a way around this one, then I will be more then happy to use what I have right now.
Which is your example
Well, first of all, no one can tell what "issue you are up against" if you dont explain.

I can't figure out your problem from the zipped up source code with out an explanarion of what you are trying to do, and the results you are currently getting.

 And the link you posted? What does it have to do with the original question you posted. Youa re adding on to your question and carrying on with this way too long.

YOur question has been answered - you need to choose a person's Asnwer you are fond of - reward him his points and move on.
If you have additional questions - then it is customary to post an additional question.

sholmes

OK, Shane.
I will close this one out here in a few.

Thanks everyone for all your help, I will close this question now, with Shane's information as the Accepted Answer.

Too bad no one could get what it was that I was really after.
But then again, sometimes it is so hard to explain to someone what you are needing
Without actually showing them face to face.

I will work on the other issue myself.

Take Care all

Carrzkiss
No, no, no - You dont have to close this question (and you surely dont have to except my answer) - you can leave this one open if it is not solved -

what i was saying is do not add onto it. If you have addutional questions, pleas post them as additional questions or in a separate question.

The question you have originally posted (I feel has been answered - I may be wrong - but i feel it has)

sholmes
CodedK;
 I gave you 20-points for that little sniplet of code that you added. As it might come in handy one day.

Shane, I gave points for each of your Example, that were working.
As they all work well, and the Posting: 04/05/2005 06:12PM EDT
From the ComboBox URL's I beleive that to be very valuable information.

This question is Closed now
Why did you award Codek part of the points?

He show you how to do a ShelLExecute - which you already knew how to do - clearly in your posted question?

Thanks! - Enjoy the code!
Shane;

   I tried my best to explain everything as clearly as I could in this question.
I tried everything within my knowledge of writting to get my point across.
And I beleive that I did do so, but unfortunantly, no one really truely understood
What it is that I am trying to do.

  Your Registry information works for the most part. And I am happy with it.
As long as the Registry Keys cannot be decrypted by any means. That I safe on that part.

  As for the last issue. It is part of the question, as it is part of the
URL in this issue. How can one work without the other.

It all comes back to the first posting on this message:
procedure TForm1.ShowPage;
ShellExecute(0, 'open',
                   PChar(''+ edit2.text +''),
                   nil, nil, SW_SHOWMAXIMIZED);
End;

But no worries.
  I have awarded the points to the answers that I feel to be usful to me, and maybe others
That (Can understand) this crazy post.

Please take care all. And if I need anything else, I will open a new question.
Shane, I did it for this

procedure TForm1.Button1Click(Sender: TObject);
begin
If Combobox1.Text:='Uk' then
ShellExecute(self.WindowHandle,'open','www.uk.com',nil,nil, SW_SHOWNORMAL);
end;

if ComboBox1.text := 'UK' then

That I never knew about.

The ShellExecute part yes, that is a no brainer.
But the way it is coded here, I think that 20-points is order for that

No worries right? I feel that this code can be of some use to me, and maybe others
So I thru him 20 - Points.
Oh sorry - i thought you were talking about the shell execute - which you all ready had correct in your question.

sholmes