Solved

New to Delphi, need some help...

Posted on 1998-10-25
10
142 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
Technology Partners: 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!

 
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
 

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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Firemonkey Need Sample for Online Shopping Example. 2 191
Strange behavior when a form is closed 6 68
oracle global variables 4 80
Convert a string into a TDateTime 5 72
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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