How to add such an inscription to the delphi so that clicking on it from the user opens its browser and opens the site that I want.
1 answer
If I understood correctly, then something like this:
procedure TForm1.Label1Click(Sender: TObject); begin // для работы этой функции, нужно подключить в раздел Uses модуль ShellAPI If (ShellExecute(Application.MainForm.Handle, PChar('open'), PChar('http://... - нужный сайт'), Nil, Nil, SW_ShowNormal)<32) Then MessageBox(0, PChar('Не могу открыть браузер!'), PChar('Ошибочка вышла!'), MB_OK + MB_ICONERROR + MB_APPLMODAL + MB_TOPMOST); end; procedure TForm1.Label1MouseEnter(Sender: TObject); begin Label1.Font.Color:=clRed; Label1.Font.Style:=[fsUnderline]; end; procedure TForm1.Label1MouseLeave(Sender: TObject); begin Label1.Font.Color:=clBlue; Label1.Font.Style:=[]; end;
- 2In general, everything is correct, but I would remove all these terrible PChar. if (ShellExecute (Handle, 'open', 'http: // ... required site', Nil, Nil, SW_ShowNormal) <32) then MessageBox (0, 'I can not open the browser!', 'A mistake was out!' , MB_OK + MB_ICONERROR + MB_APPLMODAL + MB_TOPMOST); so more compact and clear IMHO. - AlexAndR
- I did not know that these functions can perceive normal strings, so I always gave them PChar. - DelphiM0ZG
- one@ DelphiM0ZG, they cannot, but the compiler can automatically cast the stanza expression type. By the way, in D2006 there was a bug due to which you had to write explicitly. - karmadro4
|