BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using ICS Console Application

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Patrick Wong
Guest





PostPosted: Tue Nov 08, 2005 6:59 am    Post subject: Using ICS Console Application Reply with quote



Dear all,

Kindly someone help me for the captioned.

The ICS has a ConApp.pas. It benefits in providing message loop and
keyboard thread that BCB's native console applications lack of. However the
ICS is developed in Delphi and provides a ConApp.hpp for BCB calling. There
is a virtual method CreateInstance, which defined in ConApp.pas as:

class procedure TConApplication.CreateInstance(AppClass:
TConApplicationClass);
var
CMode : DWORD;
begin
FreeAndNil(ConApplication);
ConApplication := AppClass.Create(nil);
ConApplication.FIsInputRedirected := not GetConsoleMode(GetStdHandle(
STD_INPUT_HANDLE), CMode);
ConApplication.FIsOutputRedirected := not GetConsoleMode(GetStdHandle(
STD_OUTPUT_HANDLE),
CMode);
ConApplication.FThreadID := GetCurrentThreadID;
ConApplication.FKbdThread := TKeyboardThread.Create(TRUE);
ConApplication.FKbdThread.ConAppThreadID := ConApplication.FThreadID;
//SetConsoleCtrlHandler(@CtrlHandlerRoutine, TRUE);
end;

TConApplicationClass = class of TConApplication;

var
ConApplication : TConApplication;


The declaration of CreateInstance in ConApp.hpp is:

typedef TMetaClass*TConApplicationClass;

class DELPHICLASS TConApplication;
class PASCALIMPLEMENTATION TConApplication : public Classes::TComponent
{
typedef Classes::TComponent inherited;

private:
int FThreadID;
bool FTerminated;
TKeyboardThread* FKbdThread;
bool FLineMode;
AnsiString FLineBuffer;
bool FLineEcho;
bool FIsInputRedirected;
bool FIsOutputRedirected;

protected:
virtual void __fastcall Terminate(void);
virtual void __fastcall MessageLoop(void);
virtual bool __fastcall ProcessMessage(void);
virtual void __fastcall ProcessMessages(void);
virtual void __fastcall WndProc(tagMSG &Msg);
virtual void __fastcall WMKeyDown(tagMSG &MsgRec);
virtual void __fastcall WMKeyUp(tagMSG &MsgRec);
AnsiString __fastcall GetExeName();

public:
#pragma option push -w-inl
/* virtual class method */ virtual void __fastcall
CreateInstance(TMetaClass* AppClass) {
CreateInstance(__classid(TConApplication)
, AppClass); }
#pragma option pop
/* class method */ static void __fastcall
CreateInstance(TMetaClass* vmt, TMetaClass* AppClass
);
:
:
};

extern PACKAGE TConApplication* ConApplication;


I experience a simple main program to call this wrapper:

//--------------------------------------------------------------------------
-

#include <vcl.h>
#pragma hdrstop

#include <ConApp.hpp>
//--------------------------------------------------------------------------
-


TConApplication *MyConApp = NULL;
TConApplicationClass MyAppClass = NULL;

#pragma argsused
int main(int argc, char* argv[])
{
MyConApp = new TConApplication(NULL);
MyAppClass = new TMetaClass;

try
{
MyConApp->TConApplication::CreateInstance(MyAppClass);
MyConApp->Execute();
}
__finally
{
MyConApp->Done();
}

return 0;
}
//--------------------------------------------------------------------------
-

The program fails when stepped into the ConApp.pas and tried to execute:

ConApplication := AppClass.Create(nil);

The IDE CPU window pops up and it complains:

"....TestConApp.exe raised too many consecutive exceptions: 'access
violation at 0x00000000: read of address 0x00000000'"


I am too unfamiliar with Delphi so I suspect the problem is caused by my
call to the function incorrectly. In particularly, the AppClass is a class
(of TConApplicatoin) in ConApp.pas, but the ConApp.hpp asks for
TConApplicationClass, which is a pointer to TMetaClass.

Thanks in advance for any advice.
Patrick


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.