Einzelnen Beitrag anzeigen

Benutzerbild von Pseudemys Nelsoni
Pseudemys Nelsoni

Registriert seit: 24. Dez 2002
Ort: Hamburg-Harburg
3.551 Beiträge
 
#10

Re: Funktion aus Unit1 in Unit3 benutzen

  Alt 2. Dez 2003, 15:53
klar, wird zwar bisschen viel aber ....


also das ist unit1 derzeit:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ToolWin, ComCtrls, StdCtrls, XPMan, ImgList, IdBaseComponent,
  IdAntiFreezeBase, IdAntiFreeze, IdComponent, IdTCPConnection,
  IdTCPClient, IdIRC, ExtCtrls, Mask, Menus;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    XPManifest1: TXPManifest;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    GroupBox2: TGroupBox;
    ListView1: TListView;
    ToolButton6: TToolButton;
    ImageList1: TImageList;
    GroupBox3: TGroupBox;
    ListBox1: TListBox;
    GroupBox4: TGroupBox;
    ListView2: TListView;
    GroupBox5: TGroupBox;
    StatusBar1: TStatusBar;
    IdAntiFreeze1: TIdAntiFreeze;
    IdIRC1: TIdIRC;
    Memo1: TMemo;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    PopupMenu1: TPopupMenu;
    V1: TMenuItem;
    N1: TMenuItem;
    Quiz1: TMenuItem;
    Antwort1: TMenuItem;
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure IdIRC1Notice(Sender: TObject; AUser: TIdIRCUser;
      AChannel: TIdIRCChannel; Content: String);
    procedure IdIRC1Raw(Sender: TObject; AUser: TIdIRCUser; ACommand,
      AContent: String; var Suppress: Boolean);
    procedure IdIRC1UserMode(Sender: TObject; AModes: String);
    procedure IdIRC1Message(Sender: TObject; AUser: TIdIRCUser;
      AChannel: TIdIRCChannel; Content: String);
    procedure IdIRC1Quit(Sender: TObject; AUser: TIdIRCUser);
    procedure IdIRC1Part(Sender: TObject; AUser: TIdIRCUser;
      AChannel: TIdIRCChannel);
    procedure IdIRC1Parted(Sender: TObject; AChannel: TIdIRCChannel);
    procedure IdIRC1Join(Sender: TObject; AUser: TIdIRCUser;
      AChannel: TIdIRCChannel);
    procedure ToolButton4Click(Sender: TObject);
    procedure IdIRC1Kick(Sender: TObject; AUser, AVictim: TIdIRCUser;
      AChannel: TIdIRCChannel);
    procedure IdIRC1Kicked(Sender: TObject; AUser: TIdIRCUser;
      AChannel: TIdIRCChannel);
    function GetLevel(nick: string): string;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  benutzer: TStringList;

implementation

uses Unit3, Unit2;

{$R *.dfm}

function GetLevel(nick: string): string;
var
  i: integer;
  match: boolean;
  nilist, lilist: string;
begin
  match := false;
  for i := 0 to Form3.Memo1.Lines.Count-1 do
  begin
    nilist := Copy(Form3.Memo1.Lines.Strings[i], 1, Pos(':', Form3.Memo1.Lines.Strings[i])-1);
    lilist := Copy(Form3.Memo1.Lines.Strings[i], Pos(':', Form3.Memo1.Lines.Strings[i])+1, length(Form3.Memo1.Lines.Strings[i]));
    if nick = nilist then
    begin
      Result := nick + #9 + '[' + lilist + ']';
      match := true;
      break;
    end;
  end;
  if match = false then
  begin
    Result := nick + #9 + '[0]';
  end;
end;




procedure TForm1.ToolButton6Click(Sender: TObject);
begin
  Form3.ShowModal;
end;

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
  if ToolButton1.Hint = 'Verbindenthen
  begin
    ToolButton1.Hint := 'Trennen';
    ToolButton1.ImageIndex := 2;
    idIRC1.Connect;
  end
  else
  begin
    ToolButton1.Hint := 'Verbinden';
    ToolButton1.ImageIndex := 0;
    idIRC1.Disconnect;
  end;
end;

procedure TForm1.IdIRC1Notice(Sender: TObject; AUser: TIdIRCUser;
  AChannel: TIdIRCChannel; Content: String);
begin
  if auser.Nick = 'NickServthen
  begin
    if Content = 'If you do not change within one minute, I will change your nick.then
    begin
      idirc1.Say('NickServ', 'identify ...');
    end;
    if Content = 'NickServ Your nick isn''t registered.then
    begin
      idirc1.Say('NickServ', 'register ... ism' + IntToStr(Random(999999)));
      idirc1.Say('NickServ', 'link ism ...');
      idirc1.Join('#night');
    end;
    if Content = 'Password accepted - you are now recognized.then
    begin
      idirc1.Join('#night');
    end;
  end;
end;




procedure GetNicks(AUser: TIdIRCUser; ACommand, AContent: string);
begin
  Delete(AContent, 1, Pos(':', AContent));
  benutzer := TStringList.Create;
  while Pos(' ', AContent) > 0 do
  begin
    case AContent[1] of
      '*' : Delete(AContent, 1, 1);
      '!' : Delete(AContent, 1, 1);
      '@' : Delete(AContent, 1, 1);
      '%' : Delete(AContent, 1, 1);
      '+' : Delete(AContent, 1, 1);
    end;
    benutzer.Sorted := true;
    benutzer.Add(Copy(AContent, 1, Pos(' ', AContent)-1));
    Delete(AContent, 1, Pos(' ', AContent));
  end;
end;

procedure EndOfNicks(AUser: TIdIRCUser; ACommand, AContent: string);
var
  i: integer;
begin
  for i := 0 to benutzer.Count-1 do
  Form1.ListBox1.Items.Add(GetLevel(benutzer.Strings[i]));
  benutzer.free;
end;






procedure TForm1.IdIRC1Raw(Sender: TObject; AUser: TIdIRCUser; ACommand,
  AContent: String; var Suppress: Boolean);
begin
  if ACommand = '353then GetNicks(AUser, ACommand, AContent);
  if ACommand = '366then EndOfNicks(AUser, ACommand, AContent);
end;


procedure TForm1.IdIRC1UserMode(Sender: TObject; AModes: String);
begin
  idIRC1.Say('NickServ', 'identify ...');
end;

procedure TForm1.IdIRC1Message(Sender: TObject; AUser: TIdIRCUser;
  AChannel: TIdIRCChannel; Content: String);
begin
  Memo1.Lines.Add('[' + DateToStr(Now) + '][' + TimeToStr(Now) + '] (' + auser.Nick + ') ' + Content);
end;

procedure TForm1.IdIRC1Quit(Sender: TObject; AUser: TIdIRCUser);
begin
  if auser.Nick <> idirc1.Nick then
  ListBox1.Items.Delete(ListBox1.Items.IndexOf(GetLevel(auser.Nick)))
  else ListBox1.Clear;
end;

procedure TForm1.IdIRC1Part(Sender: TObject; AUser: TIdIRCUser;
  AChannel: TIdIRCChannel);
begin
  ListBox1.Items.Delete(ListBox1.Items.IndexOf(GetLevel(auser.Nick)));
end;

procedure TForm1.IdIRC1Parted(Sender: TObject; AChannel: TIdIRCChannel);
begin
  ListBox1.Clear;
  memo1.Clear;
end;

procedure TForm1.IdIRC1Join(Sender: TObject; AUser: TIdIRCUser;
  AChannel: TIdIRCChannel);
begin
  ListBox1.Items.Add(GetLevel(auser.nick));
end;

procedure TForm1.ToolButton4Click(Sender: TObject);
begin
  Form2.ShowModal;
end;

procedure TForm1.IdIRC1Kick(Sender: TObject; AUser, AVictim: TIdIRCUser;
  AChannel: TIdIRCChannel);
begin
  ListBox1.Items.Delete(ListBox1.Items.IndexOf(GetLevel(auser.Nick)));
end;

procedure TForm1.IdIRC1Kicked(Sender: TObject; AUser: TIdIRCUser;
  AChannel: TIdIRCChannel);
begin
  ListBox1.Clear;
  memo1.Clear;
end;

end.

das ist unit3:

Delphi-Quellcode:
unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, registry;

type
  TForm3 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

uses Unit1;

{$R *.dfm}

function CountTok(c: char; s: string): integer;
begin
  Result := 0;
  while Pos(c, s) > 0 do
  begin
    inc(Result);
    Delete(s, 1, Pos(c, s));
  end;
end;


procedure TForm3.Button1Click(Sender: TObject);
begin
 Close;
end;

procedure TForm3.Button2Click(Sender: TObject);
var
  reg: TRegistry;
  i, i2: integer;
  match: boolean;
  cnick, nilist: string;
begin
  reg := TRegistry.Create;
  with reg do
  begin
    RootKey := HKEY_CURRENT_USER;
    OpenKey('Software\GCC\ism v2.0', true);
    WriteString('userlist', '');
    for i := 0 to Memo1.Lines.Count-1 do
    begin
      WriteString('userlist', ReadString('userlist') + Memo1.Lines.Strings[i] + ';');
    end;
    CloseKey;
    Free;
  end;
  reg := TRegistry.Create;
  with reg do
  begin
    RootKey := HKEY_CURRENT_USER;
    OpenKey('Software\GCC\ism v2.0', true);
    WriteString('banlist', '');
    for i := 0 to Memo2.Lines.Count-1 do
    begin
      WriteString('banlist', ReadString('banlist') + Memo2.Lines.Strings[i] + ';');
    end;
    CloseKey;
    Free;
  end;
  for i := 0 to Form3.Memo1.Lines.Count-1 do
  begin
    match := false;
    for i2 := 0 to Form1.ListBox1.Items.Count-1 do
    begin
      nilist := Copy(Memo1.Lines.Strings[i], 1, Pos(':', Memo1.Lines.Strings[i])-1);
      cnick := Copy(Form1.ListBox1.Items.Strings[i2], 1, Pos(#9, Form1.ListBox1.Items.Strings[i2])-1);
      if cnick = nilist then
      begin
        Form1.ListBox1.Items.Delete(i2);
        Form1.ListBox1.Items.Add(GetLevel(cnick)); // <<< hier der fehler von wegen undefinierte bezeichner
        break;
      end;
    end;
  end;
  Close;
end;

procedure TForm3.FormCreate(Sender: TObject);
var
  reg: TRegistry;
  cKey: string;
begin
  reg := TRegistry.Create;
  with reg do
  begin
    RootKey := HKEY_CURRENT_USER;
    OpenKey('Software\GCC\ism v2.0', true);
    cKey := ReadString('userlist');
    while CountTok(';', cKey) > 1 do
    begin
      Memo1.Lines.Add(Copy(cKey, 1, Pos(';', cKey)-1));
      Delete(cKey, 1, Pos(';', cKey));
    end;
    if (Pos(';', cKey) > 0) AND (length(cKey) > 2) then
    Memo1.Lines.Add(Copy(cKey, 1, Pos(';', cKey)-1));
    CloseKey;
    Free;
  end;
  reg := TRegistry.Create;
  with reg do
  begin
    RootKey := HKEY_CURRENT_USER;
    OpenKey('Software\GCC\ism v2.0', true);
    cKey := ReadString('banlist');
    while CountTok(';', cKey) > 1 do
    begin
      Memo2.Lines.Add(Copy(cKey, 1, Pos(';', cKey)-1));
      Delete(cKey, 1, Pos(';', cKey));
    end;
    if (Pos(';', cKey) > 0) AND (length(cKey) > 2) then
    Memo2.Lines.Add(Copy(cKey, 1, Pos(';', cKey)-1));
    CloseKey;
    Free;
  end;
end;

end.
Mario
MSN: cyanide@ccode.de
  Mit Zitat antworten Zitat