1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74:
| library cl_chat; uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Buttons, ComCtrls, ToolWin, StdCtrls, ChatUnit in 'ChatUnit.pas' ;
type TCommunicate = class procedure KeyDown(Sender: TObject; var Key: Word;Shift: TShiftState); procedure ButtonClick(Sender: TObject); end;
var SendData : procedure(pName,pText:pchar); Communicator : TCommunicate; {$R *.res}
procedure SendText(Name,Text:string); begin if @SendData <> nil then begin SendData(pchar(Name),pchar(Text)); end; end;
function GetUser:string; var buffer : array[0..MAX_PATH] of Char; Size: DWORD; begin Size := sizeof(buffer); GetUserName(buffer, size); SetString(Result, buffer, lstrlen(buffer)); end;
procedure StartChat(SendAddr:pointer); begin try SendData := SendAddr; Application.CreateForm(TChatForm, ChatForm); ChatForm.RichEdit2.OnKeyDown := Communicator.KeyDown; ChatForm.SpeedButton2.OnClick := Communicator.ButtonClick; finally ChatForm.Show; end; end;
procedure GetChatText(pName,pText:pchar); begin ChatForm.RichEdit1.Lines.Add('{b'+string(pName)+'}'+':'+' '+string(pText)); end;
[color=red]procedure TCommunicate.KeyDown(Sender: TObject; var Key: Word;Shift: TShiftState); begin if key = 13 then begin SendText(GetUser,ChatForm.RichEdit2.Text); ChatForm.RichEdit2.Clear; end; end;
procedure TCommunicate.ButtonClick(Sender: TObject); begin SendText(GetUser,ChatForm.RichEdit2.Text); ChatForm.RichEdit2.Clear; end;
exports GetChatText,StartChat;
begin |