where should i place your code above
or should i create a new method for the code.
>> result := CompareText( TMyString(p1).Value, TMyString(p2).Value );
where you get TmyString(p1)
should i add 0: result?
Main Topics
Browse All Topicsdelphi
Hi how to compare a string with integer as below
example
currently im using comparetext.
when i try to sort integer value i get as below
Filename1
Filename10
Filename101
Filename2
Filename3
how to make it
Filename1
Filename2
Filename3
Filename10
Filename101
my code is below
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
a fuller example using your code...
procedure TfrmAddNU.virtualstringtre
var
testing:PRec;
begin
Testing1 := PRec(virtualstringtreeTest
Testing2 := PRec(virtualstringtreeTest
case Column of
0: begin
if length(testing1.Filename) < length(testing2.Filename) then result := -1
else if length(testing1.Filename) > length(testing2.Filename) then result := 1
else
Result := CompareText(Testing1.Filen
end;
end;
this can't work unless you write some special rules
sort a section beginning with filename and sort beginning with test, etc
but what if they differ ???
and why would you want to sort that complicated anyway ?
why not just a numeric or alphabetic sort.
users looking for a line will not know where to look,
or they will have to figure out your special rules first ???
I didn't realise "testfilename" was a possibility...
you didn't list it in your question description.
As Geert says, you will need to make some "rules"
If you can't think of the rules, then give us the biggest range of filenames you can think of, and then tell us what order they should appear in, and we'll pose some algorithms for you to choose.
Replace you CompareText function with CompareNumberedText below:
function ExtractTailNumber(AText: string): Integer;
var
Str: string;
begin
Str := Trim(AText);
// stripping the alpha character
while (Length(Str)>0) and not (Str[1] in ['0'..'9']) do
begin
Delete(Str,1,1);
end;
Result := StrToIntDef(Str, 0);
end;
function ExtractHeadString(AText: string): string;
var
Str: string;
begin
Str := Trim(AText);
Result := '';
// getting the heading the alpha character
while (Length(Str)>0) and not (Str[1] in ['0'..'9']) do
begin
Result := Result + Str[1];
Delete(Str,1,1);
end;
end;
function CompareNumberPart(AText1, AText2: string): Integer;
begin
Result := CompareValue(ExtractTailNu
end;
function CompareAlphaPart(AText1, AText2: string): Integer;
begin
Result := CompareText(ExtractHeadStr
end;
function CompareNumberedText(AText1
begin
Result := CompareAlphaPart(AText1, AText2);
if Result=0 then
Result := CompareNumberPart(AText1, AText2);
end;
Business Accounts
Answer for Membership
by: TheRealLokiPosted on 2008-09-14 at 20:25:11ID: 22475782
if length(testing1) < length(testing2) then result := -1 else if length(testing1) > length(testing2) then result := 1
else
result := CompareText( TMyString(p1).Value, TMyString(p2).Value );