Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This can be done better right? (Local drive or inter/intranet address)

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
Hi all, still busy with my little project for replacing the shortcuts littering my desktop. Got a question for you guys, I've added a new form to my project to allow inter/intranet addresses and local paths to be added in the same fashion as the programs. But here's the thing:

I've got two icons, 1 that represents local filepaths and 1 that represents inter/intranet addresses for use on my buttons. Currently this is what I use to determine which icon to use:

Code:
function LocalOrWeb(thisAddress: string): Boolean;
// true = local, false = web
begin
if thisAddress[2] = ':' then
  Result := True
  else
  Result := False;
end;

There's gotta be a 'better' way to do it than this, right?

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
first of all, I would change the name of the function:

IsLocalFile(str : string)
where a true result is indeed a local file

LocalOrWeb returning a boolean does not mean anything to me, its a confusing name.

Anyway, 2 functions come to my mind to check things out:

- to check URL you could use the PathIsURL API
- to check a file I would use the ExtractFilename and ExtractFilePath (and test these strings)

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Unfortunately, I can't use the PathIsURL as I don't seem to have it :S From what I understand it is supposed to be in ShLwAPI, whose .dcu I don't have (D7). I'll just make something myself. Too bad, was worth a try.

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
it should be available from the windows unit.

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Oh thanks whosrdaddy! I figured it was something that would be shipped with Delphi, hence I didn't even bother! But thanks, this is awesome! Sorry for the late response, I fell asleep at the computer (again) after pulling an all nighter (again).

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
Using this ShLwAPI.pas, it has brought up a question that I have been wondering about for a long time, but never actually bothered asking as it doesn't really matter "on the scale of stuff that matters".

All those functions seem to be using PChar rather than just regular string. Why is that?

(Please keep in mind that evreything that I know I have thaught myself and sometimes things just seem illogical to me, but that is probably due to me teaching myself bad habits)

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
because windows API is written in C (or C++) and C uses #0 character terminated strings (= PChar in delphi).

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top