Autor Beitrag
Lux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 19.01.05 11:41 
Hallo Leute.
Ich hab da mal eine (Wahrscheinliche Anfänger-)Frage.

Und zwar, ist es möglich, dass ich in der Function
ausblenden Delphi-Quelltext
1:
function CheckTask(Aufgaben, Array)					

wo Array steht, auch ein Array anfügen?
Ich will in der Function überprüfen, ob ein Wert in diesem Array vorhanden ist, dafür muss das Array ja in die Function gebracht werden. Geht das?

Danke schonmal im Vorraus!

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 19.01.05 11:48 
Ja, das ist Möglich, indem Du folgendes Machst:

ausblenden Delphi-Quelltext
1:
2:
3:
Type TArrayDef = Array of TDeinType;

function CheckTask(Aufgabe: TDeinType; Arr: TArrayDef):Boolean;

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 19.01.05 11:49 
ja es geht mit
ausblenden Quelltext
1:
function CheckTask(Aufgaben, Strings: array of String)					

statt String kannst du auch andere Typen nehmen
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 19.01.05 12:03 
Also ich habs nun so gemacht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function CheckTask(Aufgabe: string; Aufgabenarray: array of string):integer;
var
  i : integer;
begin
  for i := 0 to high(Aufgabenarray) do
    begin
      if(Aufgabe = Aufgabenarray[i, 1]) then result := i;
    end;
end;


Und dann die Abfrage so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure ListeInStringGrid(FN: TFileName; SG: TStringGrid);
var
  aufgabennummer: integer;
  i: Integer;
  S: string;
  Spalten, Zeilen, CountCols, CountLines, TabPos, StartPos, InitialCol: integer;
  Liste_String: TStringList;
begin
...
aufgabennummer := CheckTask(SG.Cells[Spalten,Zeilen], AAufgaben); // Zeile 74


Nun schmeißt er mir die Fehlermeldung raus:
Zitat:
[Error] functions.pas(74): Incompatible types


Zeile 74 bezieht sich auf die Ausführung der Function.

Dabei hab ich doch die functions als Type integer und auch die Variable aufgabennummer als integer deklariert...
Was mach ich denn da falsch?

Das Array ist ein Array of string.

Ps.: Ist bestimmt wieder irgendwas total leichtes wo ich wieder nicht drauf komme... ;)

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 19.01.05 12:06 
Wenn das hier die betreffende Zeile ist, würde ich mal das probieren:
ausblenden Delphi-Quelltext
1:
if(Aufgabe[i] = Aufgabenarray[i, 1]) then result := i;					


Edit: Uups...zu schnell gelesen.

Was ist denn AAufgabe für ein Typ?

_________________
We are, we were and will not be.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 19.01.05 12:09 
Hat Aufgaben bereits eine Dimension beim Aufruf?
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 19.01.05 12:09 
Aufgabe ist kein Array. Aufgabe ist eine ganz normale String Variable.
Da wird der Text reingeschrieben der sich ein einer Bestimmten Zelle in meiner Tabelle befindet.

Hatte auch vergessen zu schreiben, wo die Zeile 74 sich befindet. Das habe ich nun nachgeholt. Sorry :oops:

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 19.01.05 12:12 
Aha, hatte ich also doch nichts überlesen. ;-)

Probier mal das:

Deklariere oben den Typ
ausblenden Delphi-Quelltext
1:
type TStringArray = Array of string;					

und ersetze alle "array of string" durch "TStringArray". Könnte sein, dass er deswegen meckert.

_________________
We are, we were and will not be.


Zuletzt bearbeitet von Gausi am Mi 19.01.05 12:12, insgesamt 1-mal bearbeitet
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 19.01.05 12:12 
Gausi hat folgendes geschrieben:

Edit: Uups...zu schnell gelesen.

Was ist denn AAufgabe für ein Typ?


AAufgabe ist vom Typ Array of string


Heiko hat folgendes geschrieben:
Hat Aufgaben bereits eine Dimension beim Aufruf?

Was meinst du genau mit Dimension? Ob da schon was drin enthalten ist? Wenn du das meinst dann ja. Wie gesagt der Text aus einer Zelle meiner Tabelle ist da drin enthalten.
Verstehe leider nich genau was du mit Dimension meinst :oops:

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 19.01.05 12:19 
Gausi hat folgendes geschrieben:
Aha, hatte ich also doch nichts überlesen. ;-)

Probier mal das:

Deklariere oben den Typ
ausblenden Delphi-Quelltext
1:
type TStringArray = Array of string;					

und ersetze alle "array of string" durch "TStringArray". Könnte sein, dass er deswegen meckert.


Wenn ich das mache, schmeißt er mir die Fehlermeldung raus:
Zitat:
[Error] functions.pas(77): Incompatible types: 'Array' and 'TStringArray'


Ich hab nun allerdings auch nicht das Array an sich verändert. Also mein AAufgaben Array.
Weil da steht:
ausblenden Delphi-Quelltext
1:
AAufgaben := array[1..485, 1..4] of string;					

Dann müsste ich sonst die Mengenangabe weg machen... Kann man das denn?

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 19.01.05 12:46 
@Lux
mit Dimensionen meine ich, wieviel Variablen im array sind.
MitschL
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 211

Win 98 SE, Win 2000
D5 Pers, D6 Pers und D7 Pro
BeitragVerfasst: Mi 19.01.05 13:02 
Ähm,

AAufgaben ist ein zweidimensionales Array? Wollte die Methode nicht ein einfaches?
Mach am besten einen Type auf ein Array of String und nutze das sowohl bei der Deklaration der Methode als auch bei der Deklaration der Variablen, die da reingesteckt werden sollen.

gegrüßt!

_________________
"Bloßes Ignorieren ist noch keine Toleranz." (Theodor Fontane)
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Mi 19.01.05 16:12 
Hat auch alles nicht geklappt.
Ich hab das Problem nun anders gelöst. Zum Glück gibt es beim programmieren immer viele Wege ;)

Das einzige wo Delphi keine Fehlermeldung rausgeschmissen hat war, wenn ich beim Aufruf der Funktion beim Array auch noch angebe welches Arrayfeld ich meinte also z.B. AAufgaben[1,1];

Ich hake diese Frage nun ab, da sie für mich erledigt ist ;)

Danke für die Hilfe!

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.