Link to home
Start Free TrialLog in
Avatar of krydea
krydea

asked on

need information...(easy)

hello guy's,
i whan't to start real delphi programming so not the "what you see is what you get editor"  of borland.
but when you start a console app make it a windows app. i found a example like this:
www24.brinkster.com/2krydea/example.drp
i seard for tutorails but i could only find the "what you see is what you get editor" tutoails.
CreateWindow ). but how does it work with sockets etc..

every information is welkom. plz help.
Carlos smith
Avatar of Colin_Dawson
Colin_Dawson

Don't quite follow you problem here, seems to me that you want to use delphi, but without using the IDE?

The IDE is actually quite good (ducks the flames). The usage of TForms and descendants is optional, although is does save alot of time creating windows and stuff.  What is the point of re-inventing the wheel for every application that you write.

You can get component's to do practically anything that you want. And even if the component does not exist there it nothing stopping you from creating one.

AS for Sockets, take a look and the Indy components there free and you can get them from

http://www.nevrona.com/indy

Colin Dawson
Avatar of krydea

ASKER

yea true,
but i whant to learn how the wheel is made.:p
so you don't even know tutorails about it?
plz help.
Avatar of krydea

ASKER

<- i got socket componets in my delphi 5(TClientSocket,TServerSocket). but how to use it -> with out the "what you see is what you get editor.".
you can't say you can programme delphi if you don't know this!!!!!...............you can say you can programme borland delphi... and for myself i whant to change that..:p
ok, so you want to create objects programatically. Fine, here an example.

Procedure CreateAForm;
Var
  MyForm : TForm;
Begin
  MyForm := TForm.Create( Application ); //Application is the owner so that delphi destorys the form when the application is terminated.
  Try //Good error capturing practise
    MyForm.Caption := 'This is my Form';
    MyForm.ShowModal;
  Finally
    FreeAndNil( MyForm ); //Delphi 5 and above.
  End;
End;

The routine above will create a form then when you close the form destroy the hidden object.

You'll find it easier to create a basic form using the IDE, turn off the autocreate then modify the above code to create it.

you can also create other objects on-the-fly like TEdits and such:-)

Procedure CreateEdit( Parent : TForm );
Var
  MyEdit : TEdit;
Begin
  MyEdit := TEdit.Create( Parent ); //Create the object
  MyEdit.ParentWindow := Parent.Handle; //make sure that it's owned correctly.
  MyEdit.Visible := True;
  MyEdit.Top := 10;
  MyEdit.Left := 10;
  MyEdit.Text := 'There you go';

  //At this point we loose the refence to the Editbox, so you'll need to make the variable more globalised.
End;


I hope this is what you're getting at.

Colin D.
I tried using the TClientSocket and TServerSocket, but I'm trying to save you from alot of problems, by saying... don't bother with them, use the indy components they are WAY better and are even shipped as part of Delphi 6!

Colin Dawson.
Even better use the ICS suite of TCP/IP components.
Their really cool; I've used 'em in regular GUI apps,
in multi-threaded apps (not WYSIWYG) and they haven't
let me down - except for proxy support. But I think that's
been addressed.
http://www.rtfm.be/fpiette
Avatar of krydea

ASKER

that whas not what i asked!
Avatar of krydea

ASKER

k,
umm.... i have to use pascal to do the sockets.
so you don't got a reference or a tutorail for this stuff?
how is it called to programme delphi without the borland compiler?
I think I see what you are getting at now.

Welcome to the world of Delphi, think of it as Visual Pascal.

Basically Delphi is like Turbo Pascal 8, the WYSIWYG approach is the way that programs are written these days.  But it's got another name RAD (Rapid Application Development).

Delphi is Borlands product, it's not possible to "programme delphi without the borland compiler".  If you desire you can use delphi, to create a program without a form, then use windows API calls to generate your program.

Real Delphi Programers (like myself) simply cannot be bothered to do that everytime.  In fact the whole Ethos of delphi is geared toward code re-use.  We develop objects that will perform the task that we desire then whenever possible re-use the object as many times as possible.  We even go to the lengths of using 3rd party components, most of which are free, but there are some really good ones that you have to pay for.

As for programming sockets using only code, check out the WINSOCK API. It's supplied by microsoft and tells you exactly how to program using sockets.
Avatar of krydea

ASKER

umm do you got some urls for me?
Here's a few to get you started.


http://www.nevrona.com/indy - Really good TCP socket components
http://www.torry.net/ - you'll find just about eveything else here
http://www.delphifreestuff.com - Brad Stowers, some good stuff in here
http://delphi.icm.edu.pl/ - Delphi super page if torry don't got it, maybe it's here

There are others on the net, but these are the best that I've seen... so far.
Avatar of krydea

ASKER

hello
1.http://www.nevrona.com/indy - Really good TCP socket components
>>i don't whant componets
http://www.torry.net/ - you'll find just about eveything else here
>> that suck i know it.
http://www.delphifreestuff.com - Brad Stowers, some good stuff in here
http://delphi.icm.edu.pl/ - Delphi super page if torry don't got it, maybe it's here
i will have a look.

btw: i'm asking for tutorails for turbo pascal or the visual pascal and the sockets for that......
Avatar of krydea

ASKER

i looked and can't find anny tut or reference...:(
You won't find any.  Turbo Pascal is obsolete and I was referring to Delphi BEING visual pascal.  You are better looking for a pascal tutorial.  You should also consider looking for books, here's a couple of good ones.

Delphi 5 Developers Guide
Mastering Delphi 5

A little older but, still worth looking at is

Delphi 3 Client/Server Developers Guide.

This is more of a more rounded introduction to producing software (focusing on databases) using delphi.

It's goes into stuff like making a help file, how to use the IDE. And more importantly for you... WHY!
Avatar of krydea

ASKER

i know enuf delphi!?
but i whant the beginning so i have to seard for pascal or visual pascal?
Avatar of krydea

ASKER

umm i know why its easy but i whant just for now not the edi..
k?
plz help seards voor the non ide delphi stuff.. plz.
hmmm, looks like you really do want to do this the hard way.

don't bother searching for pascal at all.  Instead search for stuff to do with the WIN32 API.

It's a set of procedure calls that microsoft released in order to allow programmers to develop their own applications that use windows.  The best source of information for this is

http://msdn.microsoft.com

Problem is though, there's no tutorial as such. It's a reference guide to all the calls that you can do within windows.

For information: the delphi VCL is a set of wrappers that make using the WIN32 API easy to use.  The WIN32 API was renamed to the Platform SDK about 18 months ago.

If this is not what you are looking for, then I don't think I can help anymore.
Avatar of krydea

ASKER

:s not even to help me seards: i hate msdn to mutch crap:s
Avatar of krydea

ASKER

k
maybe you can help me with a pascal tutorail about winsco or socket programming?
You're using Delphi, it creates programs compatible with windows. Windows uses the WIN32 API a.k.a the Platform SDK.
The Platform SDK is produced by Mircosoft.
the best place to find out about the Platform SDK is from Microsoft.
Microsoft published the MSDN website for just that purpose.

MSDN is the most up-to-date place to get info, end of story.
Avatar of krydea

ASKER

dohh i know that,
i can't find it seards for you self you only find crap!!!!!
Avatar of krydea

ASKER

thanx for your help... but i still doesn't have a answer.
so i'm gana ask it in the pascal section!
Avatar of krydea

ASKER

not the place to ask!
I think you do have and answer, it's just not an answer that you like.
Avatar of krydea

ASKER

Avatar of krydea

ASKER

nope i don't got a answer!!
did i got a referece or a tutorail about whant i ask no
only about begin delphi programmeing dohh i know that al already i whant to know befor the wheel and then you give me msdn and that site suck's if you can find something there but no crap give it!
Avatar of krydea

ASKER

nope i don't got a answer!!
did i got a referece or a tutorail about whant i ask no
only about begin delphi programmeing dohh i know that already i whant to know befor the wheel and then you give me msdn and that site suck's if you can find something there but no crap give it!
Avatar of krydea

ASKER

no answer just comment on may work:s
Krydea, yup i have tried to get at the same information many times myself, the best i got was a unit (which my friend made) but he never turned it into a console program like i wanted :(

um, uses Winsock;

your program goes here..... check out this (this a Component).

unit DZSocket;

interface

uses
  Windows, Messages, SysUtils, Classes, WinSock, Forms;

const
  WM_WSAASYNC = WM_USER + $1;

  CONNECTSTRING = 'CONNECT %s:%d HTTP/1.0'#$0D#$0A'Host: %s'#$0D#$0A#$0D#$0A;

type
  TDZSocketErrorEvent = procedure (errormessage: String) of object;

  TDZSocketConnectEvent = procedure (IP: String; Port: Integer) of object;
  TDZSocketDisconnectEvent = procedure of object;
  TDZSocketReadEvent = procedure (Data: String) of object;

  TDZSocket = class(TComponent)
  private
    { Private declarations }
    FHandle: HWnd;
    FSocket: TSocket;
    FWSAData: TWSAData;
    FVersionRequested: Word;
    FError: Integer;
    FSockAddrIn: TSockAddrIn;
    FHostEnt: PHostEnt;
    FHost, FProxyHost: String;
    FPort, FProxyPort: Integer;
    FConnected, FProxyConnected, FUseHTTPProxy: Boolean;
    FOnError: TDZSocketErrorEvent;
    FOnConnect: TDZSocketConnectEvent;
    FOnDisconnect: TDZSocketDisconnectEvent;
    FOnRead: TDZSocketReadEvent;
    procedure WSASelectHandler(var msg: TMessage); message WM_WSAASYNC;
    procedure DZWndProc(var Message: TMessage);
    procedure RaiseError(ErrorMessage: String);
    function ReadSocket(var Buffer: String): Integer;
  protected
    { Protected declarations }
  public
    {Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Connect;
    procedure Disconnect;
    procedure SendText(const Text: String);
    function HostToIP(Host: String): String;
    function IPToHost(IP: String): String;
  published
    { Published declarations }
    property Host: String read FHost write FHost;
    property ProxyHost: String read FProxyHost write FProxyHost;
    property Port: Integer read FPort write FPort;
    property ProxyPort: Integer read FProxyPort write FProxyPort;
    property UseHTTPProxy: Boolean read FUseHTTPProxy write FUseHTTPProxy;
    property OnError: TDZSocketErrorEvent read FOnError write FOnError;
    property OnConnect: TDZSocketConnectEvent read FOnConnect write FOnConnect;
    property OnDisconnect: TDZSocketDisconnectEvent read FonDisconnect write FOnDisconnect;
    property OnRead: TDZSocketReadEvent read FOnRead write FOnRead;
  end;

procedure Register;

implementation

constructor TDZSocket.Create(AOwner: TComponent);
begin
  Inherited Create(AOwner);
  FHandle:=AllocateHwnd(DZWndProc);
  FVersionRequested:=MAKEWORD(1,1);
  FError:=WSAStartup(FVersionRequested,FWSAData);
  if error <> 0 then
    RaiseError('Unable to find a useable sockets implementation');
  if FWSAData.wVersion <> FVersionRequested then
  begin
    RaiseError('Unable to find a useable sockets version');
    WSACleanup;
  end;
  FSockAddrIn.sin_family:=AF_INET;
  FSocket:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  if FSocket = INVALID_SOCKET then
    RaiseError('Unable to create socket');
  if WSAAsyncSelect(FSocket,FHandle,WM_WSAASYNC,FD_CONNECT or FD_READ or FD_CLOSE) = SOCKET_ERROR then
    RaiseError('WSAAsyncSelect Error! :(');
end;

destructor TDZSocket.Destroy;
begin
  if FConnected or FProxyConnected then
    Disconnect;
  WSACleanup;
  DeallocateHWnd(FHandle);
  Inherited Destroy;
end;

procedure TDZSocket.DZWndProc(var Message: TMessage);
begin
  Dispatch(Message);
end;

procedure TDZSocket.WSASelectHandler(var msg: TMessage);
var
  temp, temp2: String;
begin
  case msg.LParam of
    FD_CONNECT: begin
                  if FUseHTTPProxy then
                  begin
                    FProxyConnected:=True;
                    SendText(Format(CONNECTSTRING,[FHost,FPort,FHost]));
                  end
                  else
                  begin
                    FConnected:=True;
                    if assigned(OnConnect) then
                      OnConnect(FHost, FPort);
                  end;
                end;
    FD_READ:  begin
                temp:='';
                temp2:='';
                SetLength(temp2,4096);
                while ReadSocket(temp2) <> 0 do
                  temp:=temp+temp2;
                if FUseHTTPProxy and (LowerCase(temp) = LowerCase(LowerCase('HTTP/1.0 200 Connection established'#$0D#$0A#$0D#$0A))) then
                begin
                  FConnected:=True;
                  if assigned(OnConnect) then
                    OnConnect(FHost, FPort);
                end
                else
                  if Length(Trim(temp)) > 0 then
                    if assigned(OnRead) then
                      OnRead(temp);
              end;
    FD_CLOSE: begin
                SetLength(temp,4096);
                while ReadSocket(temp) <> 0 do
                  SetLength(temp,4096);
                if assigned(OnDisconnect) then
                  OnDisconnect;
              end;
  end;
end;

procedure TDZSocket.Connect;
begin
  if not FConnected then
  begin
    if FUseHTTPProxy then
    begin
      FHost:=HostToIP(FHost);
      FSockAddrIn.sin_port:=htons(FProxyPort);
      FSockAddrIn.sin_addr.S_addr:=inet_addr(PChar(HostToIP(FProxyHost)));
    end
    else
    begin
      FSockAddrIn.sin_port:=htons(FPort);
      FSockAddrIn.sin_addr.S_addr:=inet_addr(PChar(HostToIP(FHost)));
    end;
    winsock.connect(FSocket,FSockAddrIn,SizeOf(FSockAddrIn));
  end;
end;

procedure TDZSocket.Disconnect;
begin
  if FConnected or FProxyConnected then
  begin
    winsock.shutdown(FSocket,2);
    FConnected:=False;;
    if assigned(OnDisconnect) then
      OnDisconnect;
  end;
end;

procedure TDZSocket.SendText(const Text: String);
begin
  if FConnected or FProxyConnected then
    if send(FSocket,pointer(Text)^,Length(Text),0) <> Length(text) then
      RaiseError('Unable to send data');
end;

function TDZSocket.HostToIP(Host: String): String;
var
  temp: Integer;
  addr: PChar;
begin
  Result:='';
  if Host <> '' then
  begin
    temp:=inet_addr(PChar(Host));
    if temp = -1 then
    begin
      FHostEnt:=gethostbyname(PChar(Host));
      if Assigned(FHostEnt) then
      begin
        addr:=FHostEnt^.h_addr_list^;
        if Assigned(addr) then
          Result:=Format('%d.%d.%d.%d',[byte(addr[0]),byte(addr[1]),byte(addr[2]),byte(addr[3])]);
      end;
    end;
  end;
end;

function TDZSocket.IPToHost(IP: String): String;
var
  temp: Integer;
  host: PChar;
begin
  Result:='';
  if IP <> '' then
  begin
    temp:=inet_addr(PChar(IP));
    if temp <> -1 then
    begin
      FHostEnt:=gethostbyaddr(PChar(IP),Length(IP),AF_INET);
      if Assigned(FHostEnt) then
      begin
        host:=FHostEnt.h_aliases^;
        if Assigned(host) then
          Result:=StrPas(host)
        else
          Result:='OH ****!'; //I figure it does not work :D
      end;
    end;
  end;
end;

procedure TDZSocket.RaiseError(ErrorMessage: String);
begin
  if assigned(OnError) then
    OnError(ErrorMessage);
end;

function TDZSocket.ReadSocket(var Buffer: String): Integer;
begin
  Result:=-1;
  if ioctlsocket(FSocket,FIONREAD,Result) = 0 then
  begin
    SetLength(Buffer,Result);
    winsock.recv(FSocket,pointer(Buffer)^,Result,0);
  end;
end;

procedure Register;
begin
  RegisterComponents('TDZ', [TDZSocket]);
end;

end.

going by the fact that nobody understood that you are writing a CONSOLE (little dos window people!!!!) and NOT a windows program that you can stick components onto!!!! forget the IDE just imagine using notepad people...

if you understand that above you should be able to translate it into a Console program - wish you the best of luck, if you do manage to make use of it, could you email me the program? (i simply want to read data from a webpage) just the basics? :)
Thanks -


Craig C.
Avatar of krydea

ASKER

cool, yeah i got the same problem but don't you know some notpad pepole?
Avatar of krydea

ASKER

no help..
Craig, just a quick warning. You're probably going to get flamed by krydea for that.  Here's the reason why.....


the TDZSocket is a descendant of TComponent. The TComponent is part of the VCL, and therefore part of 'the "what you see is what you get editor"  of borland.' Therefore, you cannot be 'real delphi programming'. It doesn't tell you 'how the wheel is made' as it uses the Winsock unit, which is also a part of the VCL, the Winsock is a Borland produced wrapper for the Winsock DLL that ships with Internet Explorer and many versions of windows. Also, it's not a 'referece or a tutorail' so you won't get the points.


Kydea, if you're really serious about learning how delphi works from the inside, then maybe you should purchase a couple of books on the subject.  Here's couple that I've found useful over the years


Mastering Deplhi 6
The WIN32 API bible
The Delphi 6 Developers Guide
Developing Custom Components

Of course, you do realise that some of the VCL is infact written in Assembler, so you should really learm TASM as well.
Avatar of krydea

ASKER

oke i can't give you point's for this less info..do i?
krydea:

Just a friendly reminder to return to this open question.

thanks!
amp
community support moderator
ASKER CERTIFIED SOLUTION
Avatar of craig_capel
craig_capel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial