Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Delphi - Help needed] Check if 2 strings are equal
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 24, 2008 9:47 am    Post subject: [Delphi - Help needed] Check if 2 strings are equal Reply with quote

Hey, got a bit of a problem here.
I'm using an "if and" structure, and got some problems in that.

My var section:
Code:
var
...
string1, string2: string;


They're assignment:
Code:
string1 := '';
string2 := 'test'; //Some random text


My "if and" structure:
Code:
if CONDITION1 and string1 <> string2 then
begin
...
end;


My errors (On same line, after "and"):
Code:
Incompatible types: 'String' and 'Integer'
Incompatible types: 'String' and 'Boolean'
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Jun 24, 2008 10:16 am    Post subject: Reply with quote

"if" "and" are statements, and do it like:

Code:
if string1 = string2 then


P.S - <> means !=, like if not hwnd = 0 then will be the same as if hwnd <> 0 ok ?

leave feedback
Back to top
View user's profile Send private message
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 24, 2008 10:34 am    Post subject: Reply with quote

Rot1 wrote:
"if" "and" are statements, and do it like:

Code:
if string1 = string2 then


P.S - <> means !=, like if not hwnd = 0 then will be the same as if hwnd <> 0 ok ?

leave feedback

Sorry about the statement/structure part. Wink
I've tried this:
Code:
if length(string1) > 2 then if String1 = String2 then

Doesn't work either.
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Jun 24, 2008 10:59 am    Post subject: Reply with quote

I don't know about Delphi, but in C++ you can't compare strings like that. You have to use a functions like lstrcmp.
Back to top
View user's profile Send private message
WafflesFTW
Expert Cheater
Reputation: 0

Joined: 21 Mar 2008
Posts: 131

PostPosted: Tue Jun 24, 2008 12:08 pm    Post subject: Reply with quote

Oh, your problem is simple. You are attempting to compare two variables of different types. You are comparing a string to an integer. That simply does not work. You have to make both the same type. In other words, use the "StrToInt" function on the string to convert it to an integer before comparing it with the 2. Your second error occurs, because you are testing a boolean variable(True vs. false) on a string as well. Convert the string to a boolean value, similarily, and you should not have problems.
Back to top
View user's profile Send private message AIM Address
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Jun 24, 2008 12:25 pm    Post subject: Reply with quote

tombana wrote:
I don't know about Delphi, but in C++ you can't compare strings like that. You have to use a functions like lstrcmp.
Actually you can. Altho, you need to use == operator, not =.
Code:
#include <string>

std::string s1("asd");
std::string s2("as");

if( s1 == s2 ) { /* This won't be executed */; }
s2.append("d");
if( s1 == s2 ) { /* This will be executed */; }
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Tue Jun 24, 2008 12:47 pm    Post subject: Reply with quote

Writing "if CONDITION1 and string1 <> string2 then" is like doing logical and between CONDITION1 and string1 and then check if the result equal to string2.
You should write it like "if CONDITION1 and (string1 <> string2) then".
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Jun 24, 2008 1:17 pm    Post subject: Reply with quote

Moller wrote:
Rot1 wrote:
"if" "and" are statements, and do it like:

Code:
if string1 = string2 then


P.S - <> means !=, like if not hwnd = 0 then will be the same as if hwnd <> 0 ok ?

leave feedback

Sorry about the statement/structure part. Wink
I've tried this:
Code:
if length(string1) > 2 then if String1 = String2 then

Doesn't work either.


You're now checking of the length of the strings are equal, try:

if not string1<>string2 then result:=true; //return value is true if the strings are the same

oh yeah, it's like this:

Code:
if IntToStr(String1) = IntToStr(String2) then
Back to top
View user's profile Send private message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Tue Jun 24, 2008 2:10 pm    Post subject: Reply with quote

Add parenthesis... This is how it should be:
Code:

if ((BOOLEAN condition) and (str1 = str2)) then
...
[/code]
Back to top
View user's profile Send private message
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 24, 2008 2:53 pm    Post subject: Reply with quote

Okay, I've gotten this far.
Code:
if ((length(temp) > 2) and (IntToStr(temp) = IntToStr(lastUser)) then

Now the error is:
Code:
There is no overloaded version of 'IntToStr' that can be called with these arguments
Back to top
View user's profile Send private message
WafflesFTW
Expert Cheater
Reputation: 0

Joined: 21 Mar 2008
Posts: 131

PostPosted: Tue Jun 24, 2008 3:26 pm    Post subject: Reply with quote

StrToInt, not IntToStr
Back to top
View user's profile Send private message AIM Address
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25833
Location: The netherlands

PostPosted: Tue Jun 24, 2008 4:30 pm    Post subject: Reply with quote

Code:

  if (length(temp) > 2) and (temp = lastUser) then

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
ups2000ups
I post too much
Reputation: 0

Joined: 31 Jul 2006
Posts: 2471

PostPosted: Tue Jun 24, 2008 8:38 pm    Post subject: Reply with quote

well i dont know why all started to say inttostr (since it was never an integer)

just look what DarkByte sade

_________________
dont complain about my english...
1*1 = 2?
Back to top
View user's profile Send private message
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Wed Jun 25, 2008 1:04 am    Post subject: Reply with quote

I'm sure Dark Bytes method works, but it's not what I'm in need of.
I need to make sure that temp is not equal lastUser.
I'm very sorry if I've said it the other way around.
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Wed Jun 25, 2008 1:06 am    Post subject: Reply with quote

Code:
if (length(temp) > 2) and (temp <> lastUser) then
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites