Solved

New to Delphi, need some help...

Posted on 1998-10-25
10
136 Views
Last Modified: 2010-08-05
Hi, I'm a VB programmer that is switching to Delphi and theres a few things I need some help with.  

1. In VB I used to use Left,Mid, & Right.  I couldn't find anything like that in Delphi... maybe I missed it, I don't know.  Is there anything like that in Delphi?

2. I used to use instr in VB to locate text in a string, it worked great because I could tell it where to start.  The closest thing I found in Delphi is the Pos... is there anything in Delphi thats like instr?

ohh yeah, and one last question... using a listbox how can I get the total items in it?

Thanks for the help.
0
Comment
Question by:dokken
10 Comments
 
LVL 4

Expert Comment

by:dwwang
ID: 1344262
I would like to say Delphi is a "REAL" low level programming language so there are not somany build-in functions as VB has.

You can either write some by yourself or lookup on the internet.
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344263
1: Do you mean Left$ Mid$ and Right$ ?
2: What's "Pos" for ?

maybe I could write some functions that do the same.

bryan
0
 
LVL 3

Accepted Solution

by:
bryan7 earned 60 total points
ID: 1344264
try this:

function Mid(Finalstring,Initialstring: string; InitialPos,NumberOfCharacters: Integer): string;
Var a: Integer;
begin
FinalString:= '';
for a:= InitialPos to (InitialPos + NumberOfCharacters -1 ) do
      FinalString:= FinalString + Initialstring[a];
end;

function Left(Finalstring,Initialstring: string; NumberOfCharacters: Integer): string;
Var a: Integer;
begin
FinalString:= '';
for a:= 1 to NumberOfCharacters do
      FinalString:= FinalString + Initialstring[a];
end;

function Right(Finalstring,Initialstring: string; NumberOfCharacters: Integer): string;
Var a: Integer;
begin
FinalString:= '';
for a:= Length(InitialString) downto (Length(InitialString) - NumberOfCharacters +1) do
      FinalString:= FinalString + Initialstring[a];
end;

bryan
           
0
 
LVL 17

Expert Comment

by:inthe
ID: 1344265
Hello Dokken

pos returns the index value of the first character in a specified substring that occurs in a givin string.  

and  for the listbox items it's :
edit1.text:= inttostr(listbox1.items.count);

¤¤¤¤¤¤¤ InThe ¤¤¤¤¤¤¤
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344266
And to locate text in a string:

function LocateText(TotalText,TextToFind: string, PosFrom,PosFound: Integer): Integer;
Var a,b: Integer;
      c: string;
begin
c:= '';
For  a:=  PosFrom to length(TotalText) do
    begin
          c:='';
          for b:= a to (a+length(TextToFind)-1) do
               c:= c+TotalText[b];
          if c= TextToFind then
                begin
                       PosFound:= a;
                       Exit;
                end;
    end;
PosFound:= 0;
end;

If it returns 0, then the text wasn't found.
I've not tested it with Delphi, but it should work, as Delphi is somehow like Pascal.

I'll test it later and fix any bugs if there are..

bryan


0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:dokken
ID: 1344267
Thanks for the help, you guys answered my questions perfectly!
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344268
hey dokken,

Soon I'll start with VB5, then we could exchange some knowledges about
 Delphi - VB5, what do you think ?

Give me your email, if you want so.

bryan
0
 

Author Comment

by:dokken
ID: 1344269
bryan7,

That would be cool, whats your email address?

dokken
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344270
AerithFantasy@earthling.net

AERISFANTASY@EARTHLING.NET

send a checking email.

bryan =)

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344271
sorry,  I mean,

AERITHFANTASY@EARTHLING.NET

bryan

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now