Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2006.02.19;
Скачать: [xml.tar.bz2];

Вниз

Тип String   Найти похожие ветки 

 
ArtemESC ©   (2006-01-28 08:59) [0]

Доброго времени суток...
Как в Delphi тип String устроен? В смысле
как с ним работать на асме...


 
YurikGL ©   (2006-01-28 09:02) [1]


> Как в Delphi тип String устроен?

String types

A string represents a sequence of characters. Delphi supports the following predefined string types.

String types
Type Maximum length Memory required Used for
ShortString 255 characters 2 to 256 bytes backward compatibility
AnsiString ~2^31 characters 4 bytes to 2GB 8-bit (ANSI) characters, DBCS ANSI, MBCS ANSI, etc.
WideString ~2^30 characters 4 bytes to 2GB Unicode characters; multi-user servers and multi-language applications
AnsiString, sometimes called the long string, is the preferred type for most purposes.
String types can be mixed in assignments and expressions; the compiler automatically performs required conversions. But strings passed by reference to a function or procedure (as var and out parameters) must be of the appropriate type. Strings can be explicitly cast to a different string type (see Typecasts).
The reserved word string functions like a generic type identifier. For example,

var S: string;

creates a variable S that holds a string. In the default {$H+} state, the compiler interprets string (when it appears without a bracketed number after it) as AnsiString. Use the {$H-} directive to turn string into ShortString.

The standard function Length returns the number of characters in a string. The SetLength procedure adjusts the length of a string.

Comparison of strings is defined by the ordering of the characters in corresponding positions. Between strings of unequal length, each character in the longer string without a corresponding character in the shorter string takes on a greater-than value. For example, "AB" is greater than "A"; that is, "AB" > "A" returns True. Zero-length strings hold the lowest values.

You can index a string variable just as you would an array. If S is a string variable and i an integer expression, S[i] represents the ith character--or, strictly speaking, the ith byte--in S. For a ShortString or AnsiString, S[i] is of type AnsiChar; for a WideString, S[i] is of type WideChar. For single-byte (Western) locales, MyString[2] := "A"; assigns the value A to the second character of MyString. The following code uses the standard AnsiUpperCase function to convert MyString to uppercase.

var I: Integer;
begin
 I := Length(MyString);
 while I > 0 do
 begin
   MyString[I] := AnsiUpperCase(MyString[I]);
   I := I - 1;
 end;
end;

Be careful indexing strings in this way, since overwriting the end of a string can cause access violations. Also, avoid passing long-string indexes as var parameters, because this results in inefficient code.

You can assign the value of a string constant--or any other expression that returns a string--to a variable. The length of the string changes dynamically when the assignment is made. Examples:

MyString := "Hello world!";
MyString := "Hello " + "world";
MyString := MyString + "!";
MyString := " ";               { space }
MyString := "";                { empty string }


 
begin...end ©   (2006-01-28 09:09) [2]

> ArtemESC ©   (28.01.06 08:59)

> В смысле
> как с ним работать на асме...

А что конкретно нужно?

> YurikGL ©   (28.01.06 09:02) [1]

> The following code uses the standard AnsiUpperCase function
> to convert MyString to uppercase.
>
> var I: Integer;
> begin
> I := Length(MyString);
> while I > 0 do
> begin
>   MyString[I] := AnsiUpperCase(MyString[I]);
>   I := I - 1;
> end;
> end;

Боже мой... Вот уж не ожидал такое увидеть в справке...


 
TUser ©   (2006-01-28 09:14) [3]

ansistring - указатель на область памяти, где дальше идет строка + 1 нулевой символ. А перед этой точкой - 4 байта на длину + еще дальше 4 байта на счетчик ссылок. Вроде так. При включенной опции $H (по умолчанию) - string == ansiastring.


 
ArtemESC ©   (2006-01-28 10:14) [4]

>>А что конкретно нужно?
Получить длину строки, n-символ...


 
begin...end ©   (2006-01-28 10:26) [5]

> ArtemESC ©   (28.01.06 10:14) [4]

> Получить длину строки

См. код System._LStrLen.

> n-символ

var
 S: string;
begin
 S := "abc";
 asm
   MOV   EAX, S
   MOV   AL, [EAX + ...]
   ...
 end
end


 
ArtemESC ©   (2006-01-28 10:37) [6]

>>begin...end
Спасибо!

MOV   AL, [EAX + ...]

... - это и есть смещение (от начала строки)?


 
begin...end ©   (2006-01-28 10:40) [7]

> ArtemESC ©   (28.01.06 10:37) [6]

> ... - это и есть смещение (от начала строки)?

Да. Оно на единицу меньше индекса символа.


 
ArtemESC ©   (2006-01-28 10:48) [8]

>>begin...end ©   (28.01.06 10:40) [7]
>>Оно на единицу меньше индекса символа.
Могу предположить что в первом "индексе" хранится длина?


 
begin...end ©   (2006-01-28 11:01) [9]

> ArtemESC ©   (28.01.06 10:48) [8]

См. [3]. Длина находится по смещению -4 от начала тела строки. Следовательно, получить её можно так:

var
 S: string;
begin
 S := "abc";
 asm
   MOV   EAX, S
   TEST  EAX, EAX
   JZ    @@null
   MOV   EAX, [EAX - 4] // Теперь в EAX загружена длина строки S
   ...
 @@null:
   // Строка S не инициализирована
   ...
 end
end

Говоря о том, что смещение от начала строки меньше индекса символа на единицу, я имел в виду, что символ S[1] находится по адресу Pointer(S) + 0, символ S[2] -- по адресу Pointer(S) + 1, и т.д.

P.S. Посты [5], [7] и этот относятся к случаю, когда string = AnsiString (когда {$H+}). Если же {$H-}, то string = ShortString, и получать символы и длину нужно совсем по-другому.



Страницы: 1 вся ветка

Форум: "Начинающим";
Текущий архив: 2006.02.19;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.033 c
2-1138724227
dera
2006-01-31 19:17
2006.02.19
Такая вот проблемка...


2-1138608035
Nurga
2006-01-30 11:00
2006.02.19
Как убрать контексное меню - TWebBrowser, ShockwaveFlash


15-1138776748
Ega23
2006-02-01 09:52
2006.02.19
С Днём рождения! 1 февраля


2-1138819097
pathfinder
2006-02-01 21:38
2006.02.19
Как в ADOQuery можно узнать число полученных записей?


8-1126183451
Максим
2005-09-08 16:44
2006.02.19
Конвертация цветовых схем





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский