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

Вниз

Интерфейсы под Delphi 5   Найти похожие ветки 

 
yaJohn   (2006-06-22 17:36) [0]

Есть обьект TMyObj поддерживающий некий интерфейс IMyInt. в Delphi 7 работает следующее:


var
 MyObj: TMyObj
 MyInt: IMyInt;
begin
MyObj := TMyObj.Create; //не важно откуда взялся MyObj, он есть и он типа ТMyObj
MyInt := МyObj AS IMyInt;


все работает. Но мне нужно заставить работать это под Delphi5...
Компилятор отказывается принимать конструкцию object AS interface :(

Ктонибудь помнит как это в Д5 делалось?????

Заранее спасибо.


 
Игорь Шевченко ©   (2006-06-22 17:57) [1]

"Classes that implement interfaces can use the as operator for dynamic binding on the interface. In the following example:

procedurePaintObjects(P: TInterfacedObject)

var
 X: IPaint;

begin

 X := P as IPaint;
{ statements }
end;

the variable P of type TInterfacedObject, can be assigned to the variable X, which is an IPaint interface reference. Dynamic binding makes this assignment possible. For this assignment, the compiler generates code to call the QueryInterface method of P’s IUnknown interface since the compiler cannot tell from P’s declared type whether P’s instance actually supports IPaint. At runtime, P either resolves to an IPaint reference or an exception is raised. In either case, assigning P to X will not generate a compile-time error, as it would if P was of a class type that did not implement IUnknown.

When you use the as operator for dynamic binding on an interface, you should be aware of the following requirements:

Explicitly declaring IUnknown: Although all interfaces derive from IUnknown, it is not sufficient, if you want to use the as operator, for a class to simply implement the methods of IUnknown. This is true even if it also implements the interfaces it explicitly declares. The class must explicitly declare IUnknown in its ancestor list.
Using an IID: Interfaces can use an identifier that is based on a GUID (globally unique identifier). GUIDs that are used to identify interfaces are referred to as interface identifiers (IIDs). If you are using the as operator with an interface, it must have an associated IID. To create a new GUID in your source code you can use the Ctrl+Shift+G editor shortcut key."

Ничего, что я справку цитирую ?


 
yaJohn   (2006-06-22 18:06) [2]

Премного благодарен. Тем более за цитату из справки, которую я по какому то недоразумению не нашел :(
Спасибо еще раз.



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

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

Наверх





Память: 0.45 MB
Время: 0.013 c
2-1153162403
дмитрий дельфи
2006-07-17 22:53
2006.08.06
подскажите значок градусов и оператор приостановки в делфи


4-1145340167
Виталий Панасенко
2006-04-18 10:02
2006.08.06
EAN-8, EAN-13 etc.


1-1150976550
wipr
2006-06-22 15:42
2006.08.06
Можно ли оживить QuickReport в Delphi 2006


1-1151068147
oleggar
2006-06-23 17:09
2006.08.06
нужно в Делфи 5 из файла Excel2000 считать данные


15-1152707779
Light
2006-07-12 16:36
2006.08.06
WAV файлы





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский