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 


Can you convet TStrings to Strings in delphi?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Jul 21, 2007 1:20 pm    Post subject: Can you convet TStrings to Strings in delphi? Reply with quote

Well, I was going to make an encryptor, but I don't know anything that can search and or replace a TString. So is there an function like that, or is there a way to convert TStrings to Strings.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sat Jul 21, 2007 1:49 pm    Post subject: Reply with quote

explain what a TString is
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Jul 21, 2007 2:50 pm    Post subject: Reply with quote

Well, when you make an edit box, the text is considered a string, if you make like a MemoBox or a richedit it has lines, and they are considered TStrings. Thats why if you did :

Code:

if AnsiPos('Cat', Memo1) <>0 then
Memo1.Lines := StringReplace(Memo1.Lines, 'Cat', 'c',
[rfReplaceAll, rfIgnoreCase]);


it wouldn't work because both of them are used for Strings and not TStrings. But I want to use them for my encryptor, just I can't figure out how to fix the problem, so I'm asking if I can convert TStrings into strings, or if there are two functions like AnsiPos and StringReplace used for TStrings.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
XTrinityX
Expert Cheater
Reputation: 0

Joined: 18 May 2006
Posts: 123
Location: Connecticut

PostPosted: Sat Jul 21, 2007 9:18 pm    Post subject: Reply with quote

Well, Memo1.Lines is actually an array of strings (TStrings), as you say.

You are correct that your code cannot be used because Memo1.Lines is an array of strings, while all of your functions just affect one string. You can fix this with a simple loop to loop through all the strings in Memo1.Lines and do what you want. Sample code is below.

First add i as an integer...
Code:
var
i : integer;
end;


Code:
for i := 0 to (memo1.lines.count - 1) do
begin
//Do what you want here...In this case we just replace all 'cat' with 'c.'
Memo1.Lines[i] := StringReplace(Memo1.Lines[i], 'Cat', 'c',
[rfReplaceAll, rfIgnoreCase]);
end;
Back to top
View user's profile Send private message AIM Address
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Jul 21, 2007 10:45 pm    Post subject: Reply with quote

thx, but i dont want to be spoon fed, so can you explain the code?
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sat Jul 21, 2007 10:48 pm    Post subject: Reply with quote

if you don't understand simple concepts like loops and arrays you should probably re-learn delphi. or learn another language that ISN'T object oriented and DOESN'T let you jump right into GUI programming without knowing anything.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Jul 21, 2007 10:50 pm    Post subject: Reply with quote

Well appalsap, I'm not a very good delphi programmer, and I am just learning delphi, so right now, I won't know that much and will not know so much. So if you would kindly explain the code, it would be very nice of you.

Edit:

Screw that, I never learned the Memo1.Lines[i] thing. I mean, I don't get it, it was never taugh to me. I could understandl ike Memo1.Lines[0] but [i] I don't get. The other thing that I have no idea is hte Memo1.Lines.count - 1. What is that? Just explain please or give some link to a website that explains it.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sun Jul 22, 2007 2:39 am    Post subject: Reply with quote

From my limited Delphi knowledge I would assume in this code:
Code:
for i := 0 to (memo1.lines.count - 1) do
begin
//Do what you want here...In this case we just replace all 'cat' with 'c.'
Memo1.Lines[i] := StringReplace(Memo1.Lines[i], 'Cat', 'c',
[rfReplaceAll, rfIgnoreCase]);
end;


Memo1.Lines holds the string that you got from your MemoBox.
(memo1.lines.count - 1) Counts how many elements/slots are in the array. It does the -1 probably because if you declare an array this way:
Code:
char astring[100];

It does't hold 100 elements, but 99. Because the first character of the string will be at position 0, the second character at position 1

An array looks like this [][][][][][] Thats why we added the [i] to Memo1.Lines so it can loop through each of those "boxes" and then use the StringReplace function to replace Cat with c http://delphi.about.com/library/rtl/blrtlStringReplace.htm

If by any chance you know C, here a complete tutorial: http://www.cprogramming.com/tutorial/c/lesson8.html

Yeah well it's 5AM here and probably its bad explained, you should just go read some array and loop tutorials.

_________________
Back to top
View user's profile Send private message
Simsgy
Grandmaster Cheater
Reputation: 0

Joined: 07 May 2007
Posts: 581
Location: My new avatar <3

PostPosted: Sun Jul 22, 2007 4:41 am    Post subject: Reply with quote

Well you can always use Memo1.Lines.Text to see it as String instead of TStrings, thats what I use.
_________________

Designer, WebMaster and a Delphi programmer.
TrPlayer, my biggest Delphi project hosted on SourceForge.net
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jul 22, 2007 9:03 am    Post subject: Reply with quote

Thank you UnLmtD for explaing, thank you simsgy for a much shorter way.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Jul 22, 2007 9:32 am    Post subject: Reply with quote

UnLmtD wrote:
Code:
char astring[100];

It does't hold 100 elements, but 99. Because the first character of the string will be at position 0, the second character at position 1.


I really would like to know how inebriated you are a 5 in the morning. If you declare an array to have 100 elements (because when you declare an array it starts at 1 not 0), it has 100 elements, you just loop through them from 0-99.

I am scared to see you programming drivers.

P.S. Any special reason you changed your name?
Back to top
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sun Jul 22, 2007 9:53 am    Post subject: Reply with quote

Hey Flyte
Quote:
(because when you declare an array it starts at 1 not 0)

Well, doesn't seem to be working this way, the first character of the string will be at position 0
Quote:
P.S. Any special reason you changed your name?

No, it's just that I didn't like the other one. And Dark Byte was kind enough to change it.

_________________
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Jul 22, 2007 2:54 pm    Post subject: Reply with quote

UnLmtD wrote:
Well, doesn't seem to be working this way, the first character of the string will be at position 0

Yes, when you refrence it in code, but when you are creating the array it starts at 1.

char array[0];
0, not 1, elements of char. (Impossible, defining nothing)
char array[1]; (redundant)
1 element.
char array[2];
2 elements.

Now look at the array[2], there isn't 3 elements there (0,1,2) there is 2 because it starts counting at 1. But when you use this in the code you call it like 0,1 because it starts counting at 0.
UnLmtD wrote:

No, it's just that I didn't like the other one. And Dark Byte was kind enough to change it.


I think I am going to keep calling you zomgiownyou just to bug you. Laughing
Back to top
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sun Jul 22, 2007 3:05 pm    Post subject: Reply with quote

You were right sorry Mad Thanks for explaining Razz
Flyte wrote:

I think I am going to keep calling you zomgiownyou just to bug you. Laughing

Mad I got to stop making stupid usernames, I wasn't planning to post a lot in here. =\

Offtopic: Not sleeping this night was a mistake.

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jul 22, 2007 5:18 pm    Post subject: Reply with quote

lol, i like zomgiownyou way better than UnLmtD
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
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