• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 581
  • Last Modified:

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
0
Wayne Barron
Asked:
Wayne Barron
  • 19
  • 18
  • 4
  • +2
4 Solutions
 
CodedKCommented:
Hi.

To open a browser on a specific given URL use:
   ShellExecute(self.WindowHandle,'open','www.experts-exchange.com',nil,nil, SW_SHOWNORMAL);
If the URL is not hard coded but held in a string, then it will need to be explicitly passed as a PChar:
    ShellExecute(self.WindowHandle,'open',PChar(url),nil,nil, SW_SHOWNORMAL);
This will open internet explorer on the URL supplied, or whichever is the default browser.

Usage:

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


Hope this helps.



0
 
Wayne BarronAuthor Commented:
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;
0
 
CodedKCommented:
Sorry didnt read ur question :/
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Wayne BarronAuthor Commented:
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?
0
 
CodedKCommented:
No :)
Sorry i thought that this was one of the answer-quick easy questions...
:)
Still trying to read the whole question lol...
0
 
Wayne BarronAuthor Commented:
Unfortunantly, This is not one of them.
Then again, there is probably someone that will jump in here.
And through it out.
0
 
shaneholmesCommented:
I dont know if im ready your question right or not - let me know

if ComboBox1.Text = 'USA' then
 ShellExecute(0, 'open', PChar(edtUsa.Text), nil, nil, SW_SHOWMAXIMIZED)
else
if ComboBox2.Text = 'Canada' then
 ShellExecute(0, 'open', PChar(edtCanada.Text), nil, nil, SW_SHOWMAXIMIZED)
else
if ComboBox1.Text = 'UK' then
 ShellExecute(0, 'open', PChar(edtIK.Text), nil, nil, SW_SHOWMAXIMIZED)
else


sholmes
0
 
CodedKCommented:
Thats what i understood too. :/
Or do you want to encrypt the ini file?
0
 
Wayne BarronAuthor Commented:
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?
0
 
shaneholmesCommented:
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"

0
 
Wayne BarronAuthor Commented:
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
0
 
shaneholmesCommented:
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
0
 
Wayne BarronAuthor Commented:
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
0
 
shaneholmesCommented:
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
0
 
shaneholmesCommented:
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
0
 
Wayne BarronAuthor Commented:
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.

0
 
Wayne BarronAuthor Commented:
:-)
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
0
 
mikelittlewoodCommented:
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.
0
 
mikelittlewoodCommented:
>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?
0
 
shaneholmesCommented:
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

0
 
Wayne BarronAuthor Commented:
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.
0
 
shaneholmesCommented:
How about encoded and stored in the Registry?

sholmes
0
 
shaneholmesCommented:
Alright, Im working on a sample for you.

sholmes
0
 
Wayne BarronAuthor Commented:
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.
0
 
shaneholmesCommented:
Here is the main Unit

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Edit4: TEdit;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure ComboBox1Change(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses UntReg;

{$R *.dfm}

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
 case ComboBox1.ItemIndex of
 0: Edit4.Text:= Edit1.Text;
 1: Edit4.Text:= Edit2.Text;
 2: Edit4.Text:= Edit3.Text;
 end;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
 if USAUrl <> '' then
  Edit1.Text:= USAUrl;
 if UKUrl <> '' then
  Edit2.Text:= UKUrl;
 if CANUrl <> '' then
  Edit3.Text:= CANUrl;
end;

procedure TForm1.Edit3Change(Sender: TObject);
begin
 CANURL:= Edit3.Text;
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
  UKURL:= Edit2.Text;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
 USAURL:= Edit1.Text;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 USAURL:= Edit1.Text;
 UKURL:= Edit2.Text;
 CANURL:= Edit3.Text;
end;

end.
 
0
 
shaneholmesCommented:
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.
0
 
shaneholmesCommented:
Let me know if you want me to email you the application (zipped up) - its small

I would need your email

sholmes
0
 
shaneholmesCommented:
Oops I forgot this part!

procedure TForm1.Button1Click(Sender: TObject);
begin
 ShellExecute(Application.Handle,PChar('open'),PChar(edit4.Text),PChar(''),nil,SW_NORMAL);
end;
0
 
mikelittlewoodCommented:
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?
0
 
Wayne BarronAuthor Commented:
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:
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
0
 
Wayne BarronAuthor Commented:
Here you go.
This way you will better understand what is going on

http://www.carrz-fox-fire.com/1/Q_21377601.zip
0
 
Wayne BarronAuthor Commented:
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.
0
 
shaneholmesCommented:
This updated unit adds the Encryption

unit UntReg;

interface

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


function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer):string;
function Decrypt(const InString:string; StartKey,MultKey,AddKey:Integer):string;

procedure ReadRegistry;
procedure WriteRegistry;

var
 USAUrl, UKUrl, CANUrl: String;

implementation

function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer):
string;
var
  I : Byte;
begin
  Result := '';
  for I := 1 to Length(InString) do
  begin
    Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
    StartKey := (Byte(Result[I]) + StartKey) * MultKey + AddKey;
  end;
end;

function Decrypt(const InString:string; StartKey,MultKey,AddKey:Integer):
string;
var
  I : Byte;
begin
  Result := '';
  for I := 1 to Length(InString) do
  begin
    Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
    StartKey := (Byte(InString[I]) + StartKey) * MultKey + AddKey;
  end;
end;



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', Encrypt(USAUrl,10,20,30));
     Reg.WriteString('UK Url', Encrypt(UKUrl, 10, 20, 30));
     Reg.WriteString('CAN Url', Encrypt(CANUrl, 10, 20, 30));
     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:= Decrypt(Reg.ReadString('USA Url'), 10, 20, 30);
     if Reg.ValueExists('UK Url') then
      UKUrl:=  Decrypt(Reg.ReadString('UK Url'), 10, 20, 30);
     if Reg.ValueExists('CAN Url') then
      CANUrl:=  Decrypt(Reg.ReadString('CAN Url'), 10, 20, 30);
     Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;


initialization
 ReadRegistry;
finalization
 WriteRegistry;
end.
0
 
ginsonicCommented:
Whay don' crypt the ini dates? And decrypt when need to use it.
0
 
Wayne BarronAuthor Commented:
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
0
 
shaneholmesCommented:
Did you not like my example?

sholmes
0
 
Wayne BarronAuthor Commented:
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:
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
0
 
shaneholmesCommented:
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

0
 
Wayne BarronAuthor Commented:
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
0
 
shaneholmesCommented:
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
0
 
Wayne BarronAuthor Commented:
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
0
 
shaneholmesCommented:
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!
0
 
Wayne BarronAuthor Commented:
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.
0
 
Wayne BarronAuthor Commented:
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.
0
 
shaneholmesCommented:
Oh sorry - i thought you were talking about the shell execute - which you all ready had correct in your question.

sholmes
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 19
  • 18
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now