Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
POS function
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Offical launch of the 1 B...
by
Gustavo 'Gus' Carreno
[
Today
at 05:53:09 am]
Parquet?
by
ron.dunn
[
Today
at 04:01:19 am]
how to change the color f...
by
Joanna
[
Today
at 03:23:43 am]
A "leisure" question on W...
by
Joanna
[
Today
at 03:20:06 am]
Big Numbers Math
by
woodybrison
[
Today
at 01:30:21 am]
Project fails on run but ...
by
jamie
[
Today
at 12:54:49 am]
Curling Pythagoras Tree: ...
by
Boleeman
[
Today
at 12:00:37 am]
Ribbon bar in Lazarus 3.2...
by
wp
[March 28, 2024, 11:29:17 pm]
Free AI to use in local
by
BSaidus
[March 28, 2024, 10:57:23 pm]
how to search in rxmemory...
by
rcmz
[March 28, 2024, 10:19:54 pm]
Configure JCF messages
by
GordonFindlay
[March 28, 2024, 10:16:19 pm]
Poll: Watches and Display...
by
Martin_fr
[March 28, 2024, 10:15:08 pm]
Dialog ShowModal and an i...
by
d7_2_laz
[March 28, 2024, 09:51:39 pm]
JEDI error but unit compi...
by
Thaddy
[March 28, 2024, 09:30:33 pm]
Understanding and adjusti...
by
circular
[March 28, 2024, 09:09:56 pm]
Controlling the behavior ...
by
wp
[March 28, 2024, 08:29:28 pm]
Dynarray initialization p...
by
Thaddy
[March 28, 2024, 06:30:12 pm]
Zeos components. Had to c...
by
Fantablup
[March 28, 2024, 04:17:13 pm]
[SOLVED] Completion box s...
by
furious programming
[March 28, 2024, 04:12:26 pm]
[LAMW] How to create a ca...
by
af0815
[March 28, 2024, 03:48:16 pm]
Complex package installat...
by
wp
[March 28, 2024, 03:38:16 pm]
[SOLVED] Combined pointer...
by
CM630
[March 28, 2024, 02:48:41 pm]
Using KeyPress event, how...
by
Zvoni
[March 28, 2024, 02:24:42 pm]
a Unit problem?
by
Thaddy
[March 28, 2024, 01:56:12 pm]
Any upgrades to fpWeb pag...
by
marcov
[March 28, 2024, 12:50:25 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: POS function (Read 22233 times)
Sora-Kun
Full Member
Posts: 162
I can smell your presence ...
POS function
«
on:
June 07, 2010, 11:19:06 am »
Hello,
I'm trying to search for word in a TSYNEDIT, using the pos function, { ex: ch:= SynEdit1.Text; p:=pos(word,ch); }
but the function return 0. What's the probleme and how can I fix it. Thanks =)
Logged
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.
Made in Lazarus.
Soon, in The WWW.
cdbc
Hero Member
Posts: 1026
Re: POS function
«
Reply #1 on:
June 07, 2010, 11:29:13 am »
Hi
When Pos-function returns 0, it means the substring you are searching for, isn't present in the source string.
hth
Regards Benny
Logged
If it ain't broke, don't fix it
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0
Sora-Kun
Full Member
Posts: 162
I can smell your presence ...
Re: POS function
«
Reply #2 on:
June 07, 2010, 11:34:42 am »
yeah I know that I have 2 years TURBO PASCAL experience on console and algorithme but I'm new to the graphic world in pascal.. however, the word exsists but the function return 0 here is the code :
procedure TForm1.BitBtn20Click(Sender: TObject);
var x:integer; msg,ch: string;
begin
ch:= SynEdit1.Text;
word := search.Text;
n:=0;
x:=0;
repeat
begin
x := pos(ch,word);
str(x,msg);
MessageDlg(msg,mtCustom, [mbOK], 0);
n := n+1;
tab[n]:= x;
delete(ch,x,length(word));
end;
until (x = 0);
if ( n <> 0 ) and ( n <> 1) then
begin
next.Enabled:=true;
previous.Enabled:=true;
end;
f:=n;
str(n,msg);
Label4.Caption:= (msg+' Word(s) found.');
if (f = 1) then begin
SynEdit1.SelStart:=(tab[n]+length(word)*n - length(word));
SynEdit1.SelEnd:= (tab[n]+length(word)*n);
end;
n:=1;
end;
and when I see the Dialog message it contains 0.
Help
Logged
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.
Made in Lazarus.
Soon, in The WWW.
mas steindorff
Hero Member
Posts: 532
Re: POS function
«
Reply #3 on:
June 07, 2010, 11:37:05 am »
from the help file at:
http://www.freepascal.org/docs-html/rtl/system/pos.html
Description
Pos returns the index of Substr in S, if S contains Substr. In case Substr isn't found, 0 is returned. The search is case-sensitive.
The docs are good resource for simple items like this. Do a search on "help" in Lazarus to see how the different resources available to you. the simplest is to Highlight the keyword and press F1.
Logged
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases
theo
Global Moderator
Hero Member
Posts: 1927
Re: POS function
«
Reply #4 on:
June 07, 2010, 11:44:22 am »
It's simple: Instead of trying to find the bug, you are posting to the forum.
You write in your first message:
p:=pos(word,ch);
But you do in your code:
x := pos(ch,word)
Logged
Sora-Kun
Full Member
Posts: 162
I can smell your presence ...
Re: POS function
«
Reply #5 on:
June 07, 2010, 02:07:32 pm »
lol yeah sorry
and thanks
Logged
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.
Made in Lazarus.
Soon, in The WWW.
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
POS function
TinyPortal
© 2005-2018