![]() |
Msn contact list
First of all i wrote this code second of all it dosen't work as it should.Well what i want to do is that it adds only people with certain status to the list.
Delphi-Quellcode:
const MISTATUS_UNKNOWN = $00000000; MISTATUS_OFFLINE = $00000001; MISTATUS_ONLINE = $00000002; MISTATUS_INVISIBLE = $00000006; MISTATUS_BUSY = $0000000A; MISTATUS_BE_RIGHT_BACK = $0000000E; MISTATUS_IDLE = $00000012; MISTATUS_AWAY = $00000022; MISTATUS_ON_THE_PHONE = $00000032; MISTATUS_OUT_TO_LUNCH = $00000042; MISTATUS_LOCAL_FINDING_SERVER = $00000100; MISTATUS_LOCAL_CONNECTING_TO_SERVER = $00000200; MISTATUS_LOCAL_SYNCHRONIZING_WITH_SERVER = $00000300; MISTATUS_LOCAL_DISCONNECTING_FROM_SERVER = $00000400; function contactslist(status:MISTATUS):string; var MSNMessenger: IMessenger; MSNMyContacts: IMessengerContacts; MSNMyContact: IMessengerContact; v_Count: Integer; begin for v_Count := 0 to MSNMyContacts.Count - 1 do begin if MSNMyContact.Status=status then // <<< compiler shows error here!!! MSNMyContact := (MSNMyContacts.Item(v_Count) as IMessengerContact); result:= MSNMyContact.FriendlyName + ' ' +MSNMyContact.FriendlyName; end; end; procedure TfrmMain.Button2Click(Sender: TObject); begin ListBox1.Items.Add(contactslist( MISTATUS_ONLINE)); end; |
Re: Msn contact list
Could you tell us the error message - maybe we could help you then :roll:
But obviously you are trying to use an unreferenced interface - How do you think this should work exactly? |
Re: Msn contact list
This gets contact list it just doesnt get what i want:( to get list with status.
--------------------------- Debugger Exception Notification --------------------------- Project MSNMessengerAPIController.exe raised exception class EAccessViolation with message 'Access violation at address 0047F15B in module 'MSNMessengerAPIController.exe'. Read of address 00000000'. --------------------------- Break Continue Help --------------------------- |
Re: Msn contact list
Try to debug it, so you can tell us in wich line the exception is raised
|
Re: Msn contact list
Zitat:
|
Re: Msn contact list
You access MSNMyContacts without initializing it first. Btw, you should really format your code properly.
|
Re: Msn contact list
Zitat:
|
Re: Msn contact list
Initilized but still same error and this gets me thinking :roll:
Even if i change the line order still the same error
Delphi-Quellcode:
if MSNMyContact.Status=status then BEGIN for v_Count := 0 to MSNMyContacts.Count - 1 do MSNMyContact := (MSNMyContacts.Item(v_Count) as IMessengerContact); result:= MSNMyContact.FriendlyName + ' ' +MSNMyContact.FriendlyName;
Delphi-Quellcode:
function contactslist(status:MISTATUS):string;
var MSNMessenger: IMessenger; MSNMyContacts: IMessengerContacts; MSNMyContact: IMessengerContact; v_Count: Integer; begin MSNMessenger := MessengerAPI_TLB.CoMessenger.Create; MSNMyContacts := (MSNMessenger.MyContacts as IMessengerContacts); for v_Count := 0 to MSNMyContacts.Count - 1 do begin if MSNMyContact.Status=status then BEGIN MSNMyContact := (MSNMyContacts.Item(v_Count) as IMessengerContact); result:= MSNMyContact.FriendlyName + ' ' +MSNMyContact.FriendlyName; end; end; end; |
Re: Msn contact list
If you wanna pour water out of an bottle, you have to open it first. You still evaluate an reference before you ajust it to an object!!!
|
Re: Msn contact list
MISTATUS is ToleEnum
|
Re: Msn contact list
Zitat:
Zitat:
As you been told before, You have to assign it first! |
Re: Msn contact list
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:
How can it point to nil if you define it in variable in function
Delphi-Quellcode:
const
MISTATUS_UNKNOWN = $00000000; MISTATUS_OFFLINE = $00000001; MISTATUS_ONLINE = $00000002; MISTATUS_INVISIBLE = $00000006; MISTATUS_BUSY = $0000000A; MISTATUS_BE_RIGHT_BACK = $0000000E; MISTATUS_IDLE = $00000012; MISTATUS_AWAY = $00000022; MISTATUS_ON_THE_PHONE = $00000032; MISTATUS_OUT_TO_LUNCH = $00000042; MISTATUS_LOCAL_FINDING_SERVER = $00000100; MISTATUS_LOCAL_CONNECTING_TO_SERVER = $00000200; MISTATUS_LOCAL_SYNCHRONIZING_WITH_SERVER = $00000300; MISTATUS_LOCAL_DISCONNECTING_FROM_SERVER = $00000400; function contactslist(status:[b]MISTATUS[/b]):string; |
Re: Msn contact list
Zitat:
It seems you don't know much about oop! |
Re: Msn contact list
Ofcourse i don't,i am a beginer in delphi programing i know like 13% of delphi.
Bascily what i want to do is filter the contacts by status thats all.. |
Re: Msn contact list
Well?
|
Re: Msn contact list
As you told severall times before you just can evaluate after assigning the reference to an object!
|
Re: Msn contact list
Can you show a working example couse i don't know what you are talking about.
|
Re: Msn contact list
Reread my answers
|
Re: Msn contact list
An object in Delphi is actually a 4 byte long pointer to a structure in the memory (on the heap). At the beginning, the pointer contains a random adress (often nil, but it could be whatever value the register had before). So we have to create the structure in the memory first and then remember the adress of this structure in the variable.
We do this by writing something like this:
Delphi-Quellcode:
A class (e.g. TStringlist) describes "what the object does", which properties and which methods it has. Classes are something like "construction plans" for objects. If we build the object described in the construction plan, we call this object an instance (of the class).
var
MyStringlist: TStringlist; // declare the variable stringlist as an instance of a tstringlist-class. begin MyStringlist := TStringlist.Create; // Create the Stringlist-object // Now we can use the object MyStringlist.LoadFromFile('readme.txt'); MyStringlist.Free; // Destroy the object and free the allocated memory end; So, one of the coolest things about OOP is, that you can extend (or inherit) classes. When declaring a new class, you can tell Delphi to build this class based on a class that already exists (the parent). Now the new class contains all methods and properties of the parent plus some extra features. Because the child contains everything of the parent (the classes are compatible), you can assign instances of child classed to their parent classes. This works only in one direction of course. For example the TStrings-class has basic properties and methods to work with text. The TStringlist-class extends the class by adding some methods like sorting and saving the data to a file and loading it (i think). Now we can do something like this:
Delphi-Quellcode:
This gets really interesting when it comes to overriding methods. "Strings.Clear" in line 3 is a bad example because it calls the same method for both TStrings and TStringlist (TStringlist doesn't override it). But classes can also override methods of their parents (if the method is declared as "virtual" in the parent class). Then one line can call different methods depending on which class the object is an instance of.
procedure DoSomething(Strings: TStrings); // Note that the parameter is declared as TStrings
begin Strings.Clear; // deletes the text contained in "Strings". Just some random example... end; var MyStringlist: TStringlist; // Note that we use a TStringlist begin MyStringlist := TStringlist.Create; MyStringlist.LoadFromFile('readme.txt'); DoSomething(MyStringlist); // This works now, because TStrings is the parent of TStringlist, therefore TStringlist has everything TStrings has. MyStringlist.Free; end; Look at the TGraphic class. The base class doesn't even do anything except declaring the methods used by the children (TBitmap, TJPEGImage and so on...). All codes for loading the image formats are implemented in the child classes and override the methods of the base class. This way, we can work with graphic without knowing which format they have. Now because most of the methods of the base class don't contain any code, they are marked as "abstract". When trying to call them directly, you get an exception stating something like "abstract error". A more flexible alternative to those only abstract objects are interfaces. Interfaces may not contain code. They only describe which functionality an object must have. This way a program (or a programmer) doesn't have to care about each individual implementaion as long as it supports the interface. Whatever the object behind the interface is, it doesn't matter, the code stays the same. This is how I understand interfaces. What you have done, is, you have declared some variables as interfaces (IMessenger, IMessengerContacts, IMessengerContact), but you haven't assigned any instances to them. Remember, interfaces only describe the functionality, but they don't contain any themselves. I hope you understand my explanation. Please note that I haven't really worked with interfaces yet myself (except for reading out XML files). If I left out something, please search for a tutorial about OOP, I'm sure there are plenty of them on the internet. |
Re: Msn contact list
Guyz the code works its just the
Delphi-Quellcode:
this is making problems.Code WORKS WAKE UP lol IT WORKS!! i just want to filter the contacts. :)
if MSNMyContact.Status=status then BEGIN
|
Re: Msn contact list
Zitat:
|
Re: Msn contact list
I did read it twice!Its just that code it self works without that line;)
|
Re: Msn contact list
Yes and we told you the reason for that. But maybe we're justs idiots :wall:
|
Re: Msn contact list
Zitat:
Maybe that's what you understand :wall: Just do what you've been told multiple times! |
Re: Msn contact list
Actually it dosen't work?
--------------------------- Debugger Exception Notification --------------------------- Project Project3.exe raised exception class EOleSysError with message 'Unspecified error'. --------------------------- Break Continue Help ---------------------------
Delphi-Quellcode:
class function CoMessenger.Create: IMessenger4;
begin Result := CreateComObject(CLASS_Messenger) as IMessenger4; <<brake end; |
Re: Msn contact list
So nobody knows? :?
|
Re: Msn contact list
Stop ignoring solutions posted here
|
Re: Msn contact list
There are no solutions i dont see no code!And excuse me to ask it becouse i dont know OOP ok?I am a beginer for christ sakes. :shock:
|
Re: Msn contact list
|
Re: Msn contact list
Why am i wasting my time here? :lol:
|
Re: Msn contact list
Zitat:
* closed * |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:17 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz