Autor Beitrag
Tigu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Mi 11.01.06 18:28 
Hallo!
Wir müssen im Infounterricht Kalsse 12 ein Buchstabenrätsel für Delphi7 programieren. Teile des Programmes funktionieren schon, aber für den Rest bräuchte ich einen Denkanstoß und Hilfe von euch.
In dem Quelltext, welcher sich im Anhang befindet, funktioniert es, dass der erste Buchstabe des eingegebenen Wortes gesucht und markiert wird.
Wie schreibe ich die Schleife aber für die weiteren Buchstaben. Meiner Meinung nach, muss ich das Programm überprüfen lassen, ob es zu allen Seiten weitere Buchstaben gibt und danch nach einem weiteren Suchwort-Buchstaben suchen lassen.
Schon mal danke für eure Hilfe :les:
Tigu



Quelltext:

ausblenden volle Höhe Delphi-Quelltext
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:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Feld: TStringGrid;
    Label1: TLabel;
    BnEnde: TButton;
    Buchstaben_liste: TListBox;
    BnEintragen: TButton;
    BnSuchen: TButton;
    Edit1: TEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure BnEndeClick(Sender: TObject);
    procedure BnEintragenClick(Sender: TObject);
    procedure eintragen;
    procedure FeldDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure BnSuchenClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var x,y:integer;
begin
 if fileexists('buchstaben_liste.txt') then
 begin
 buchstaben_liste.Items.LoadFromFile('buchstaben_liste.txt');
 end;

 for x:=feld.fixedCols to feld.ColCount -1 do
 feld.Cells[x,0]:=chr(65+x-1);
 for y:=feld.fixedRows to feld.RowCount-1 do
 feld.Cells[0,y]:=IntToStr(y);
end;

procedure TForm1.eintragen;
var x,y:integer;
begin
buchstaben_liste.Itemindex:=0;
for y:=1 to feld.ColCount -1 do
  begin
    for x:=feld.FixedRows to feld.RowCount -1 do
    begin
    feld.Cells[x,y]:=buchstaben_liste.Items[buchstaben_liste.Itemindex];
    buchstaben_liste.ItemIndex:=buchstaben_liste.Itemindex+1;
    end;
  end;
end;

procedure TForm1.BnEintragenClick(Sender: TObject);
begin
eintragen;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
eintragen;
end;

procedure TForm1.BnEndeClick(Sender: TObject);
begin
close;
end;
procedure TForm1.FeldDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
  var s:string;
begin
 s:=feld.Cells[acol,arow];
 if length(s)>0 then
    if s[1] in ['a'..'z'] then
      begin
      feld.Canvas.Rectangle(Rect);
      feld.Canvas.Font.Color:=clred; //Buchstabenfarbe
      feld.Canvas.TextOut(Rect.Left+2,rect.Top+2,s);
      feld.Canvas.Font.Color:=clblack;
      end;
end;

procedure TForm1.BnSuchenClick(Sender: TObject);
var x,y,a:integer;
    Suchwort:string;
begin
Suchwort:=Edit1.Text;
 for y:=1 to feld.RowCount -1 do
  begin
   for x:=feld.FixedCols to feld.colcount -1 do
   begin
     if feld.Cells[x,y] = Suchwort[1] then
feld.Cells[x,y]:=lowercase(feld.Cells[x,y]);
     //for a:=1 to length(suchwort) do          suchwort[a]
end;
end;
end;

end.


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
Einloggen, um Attachments anzusehen!


Zuletzt bearbeitet von Tigu am Fr 13.01.06 16:58, insgesamt 2-mal bearbeitet
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 11.01.06 18:33 
Kannst du den Code nicht hier im Beitrag posten, einfach auf edit klicken und den code in delphi tags einfügen, dann muss sich das nicht jeder laden und dir kann schneller geholfen werden ;)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 11.01.06 19:12 
@ tigu:

1. Bitte Delphi-Tags verwenden!
2. Könntest du mal das gesamte Projekt hochladen, damit sich besser reinfindet :wink:

Greetz Koller

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Fr 13.01.06 17:02 
Hallo Koller!
Im Anhang ist der funktionierende Teil des Programmes zum Angucken und Probieren.
Danke schon einmal für deine Hilfe :lupe:
Tigu
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 13.01.06 17:12 
Hallo,

also hab mir das Prog geladen.

Wenn ich auf Eintragen klicke, kommt eine Fehlermeldung. Im Code steht, dass der ITemIndex von buchstaben_liste auf 0 gesetzt wird. Weiterhin steht dort, dass es eine Listbox ist. Aber ich sehe nur ein Stringgrid, ein Edit und vier Buttons. Wo ist sie hin?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: So 15.01.06 14:05 
Hallo Koller!
Das mit der Fehlermeldung könntze leider daran liegen, dass ich die Buchstaben aus einem Edittext auslesen lasse und die Listbox befindet sich unter dem Edit.
Tigu
Einloggen, um Attachments anzusehen!