![]() |
SetLength und type?
Hi!
Kann mir jemand sagen, was ich da falsch mache?
Delphi-Quellcode:
Es kommt immer dieser Fehler:
procedure TForm1.ArrayFuellen(var TArray: array of string);
begin SetLength(TArray, ListBox1.Count); ... end; Zitat:
|
Re: SetLength und type?
Du musst einen Typen definieren ;-)
Delphi-Quellcode:
...:cat:...
type
TStringArray = array of string; procedure TForm1.ArrayFuellen(var TArray: TStringArray); begin SetLength(TArray, ListBox1.Count); ... end; |
Re: SetLength und type?
Danke, aber das hab ich gemacht, geht trotzdem nicht.
Und bei meinen anderen proceduren, die ähnlich aufgebaut sind, muss ich den typen auch nicht definieren. |
Re: SetLength und type?
Moin Matze,
TArray ist nicht zufälliger Weise ein Typangabe? |
Re: SetLength und type?
Zitat:
Außerdem geht das trotzdem nicht. :( |
Re: SetLength und type?
Dann versuche es doch mal, die Variable anders zu benennen.
Code:
...:cat:...
type
TStringArray = array of string; procedure TForm1.ArrayFuellen(var [color=#ff0000]SomeArray[/color]: TStringArray); begin SetLength([color=#ff0000]SomeArray[/color], ListBox1.Count); ... end; |
Re: SetLength und type?
Moin Matze,
die Reihenfolge ist aber Bezeichner : Typangabe. Bei Dir steht also Typangabe : Typangabe. Das kann ja nicht funktionieren. |
Re: SetLength und type?
Zitat:
Delphi-Quellcode:
@sakura: Ich kappiere das irgendwie nicht so richtig. Bei mir geht das auch nicht.
procedure TForm1.GibAus(var TArray: array of string);
var i: integer; begin for i := 0 to Length(TArray)-1 do ListBox1.Items.Add(TArray[i]); end; |
Re: SetLength und type?
Zitat:
Delphi-Quellcode:
...:cat:...
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TStringArray = array of string; type TForm1 = class(TForm) ListBox1: TListBox; private { Private declarations } public { Public declarations } procedure ArrayFuellen(var SomeArray: TStringArray); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.ArrayFuellen(var SomeArray: TStringArray); begin SetLength(SomeArray, ListBox1.Count); end; end. |
Re: SetLength und type?
Moin Matze,
meine Aussage mit dem "Kann ja nicht funktionieren" bezog sich darauf, das TArray eine Typenangabe ist, was in Deinem Beispiel wohl offensichtlich nicht zutrifft. Einen Argumentbezeichner mit T beginnen zu lassen ist allerdings unglücklich, da dieser Buchstabe, gemäss Konvention für Typen vorgesehen ist. Argumente sollten besser mit einem A beginnen. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:20 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz