### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Writing a function  (Read 492 times)

#### JLWest

• Hero Member
• Posts: 877
##### Writing a function
« on: January 27, 2020, 07:25:46 pm »
You will know the first function as a FP supplied function.

function TryStrToInt( const s: string;  out i: LongInt) : Boolean;

I would like a function that searches a table for an item and returns a boolean value. If true it puts a code in the "out" parm p. The table looks like the following.

AAAAAAA AAA
BBBBBBB BBB
DDDDDD DDD

So I would call:

Var
Valid : Boolean = False;
P     String = '';
begin
Valid :=  TryValidEntry('DDDDD', P); //and get Valid = True and P = 'DDD'.

Or am I all wrong on this.

function TryValidEntry( const S : String;  out P : String) : Boolean;

Thanks;
FPC 3.2.0, Lazarus IDE v2.0.4
Windows 10 Pro 32-GB
Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

#### Handoko

• Hero Member
• Posts: 3851
• My goal: build my own game engine using Lazarus
##### Re: Writing a function
« Reply #1 on: January 27, 2020, 07:34:05 pm »
function TryValidEntry( const S : String;  out P : String) : Boolean;

Yes, that is correct.

#### JLWest

• Hero Member
• Posts: 877
##### Re: Writing a function
« Reply #2 on: January 27, 2020, 07:46:39 pm »
function TryValidEntry( const S : String;  out P : String) : Boolean;

Yes, that is correct.

Thanks, I'll try and write the code.

Yea, it worked. For some reason I thought they were  provided specialized function. (with the Out parm )
« Last Edit: January 28, 2020, 01:13:43 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
Windows 10 Pro 32-GB
Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB