![]() |
Was ist eine variable "Variant"
Was ist/heist "Variant" (in meinen fall : excel: variant;) und was kann ich dafür einstezten? Ich brauche es für diese
![]() |
Re: Was ist eine variable "Variant"
![]() |
Re: Was ist eine variable "Variant"
Ein Variant ist ein varianter (wechselbarer) Datentyp.
Beispiel:
Delphi-Quellcode:
var
vari: variant; text: string; int: integer; begin int := 25; // integer füllen vari := int; // in die variante packen text := vari; // die variante kann auch ein text sein... ShowMessage(text); // der ausgegeben wird end; |
Re: Was ist eine variable "Variant"
:wiejetzt:
Sorry aber ich hab da keinen durchblick ( bzw. ich raffs nich). :duck: Wie bezieht sich das auf meine funktion? |
Re: Was ist eine variable "Variant"
@Phoenix: vielen dank..
..aber das hilft mir leider nicht weiter bei meinen Problem mit folgender function
Delphi-Quellcode:
Ich will damit ein excel worksheet in ein stringgrid machen :
Function ExcelCopyToStringGrid(
Excel : Variant; ExcelFirstRow : Integer; ExcelFirstCol : Integer; ExcelLastRow : Integer; ExcelLastCol : Integer; StringGrid : TStringGrid; StringGridFirstRow : Integer; StringGridFirstCol : Integer; SizeStringGridToFit : Boolean; {Make the StringGrid the same size as the input range} ClearStringGridFirst : Boolean {cells outside input range in StringGrid are cleared} ): Boolean; Var C,R : Integer; Begin Result := False; If ExcelLastCol < ExcelFirstCol Then Exit; If ExcelLastRow < ExcelFirstRow Then Exit; If (ExcelFirstRow < 1) Or (ExcelFirstRow > 255) Then Exit; If (ExcelFirstCol < 1) Or (ExcelFirstCol > 30000) Then Exit; If (ExcelLastRow < 1) Or (ExcelLastRow > 255) Then Exit; If (ExcelLastCol < 1) Or (ExcelLastCol > 30000) Then Exit; If StringGrid = nil Then Exit; If SizeStringGridToFit Then Begin StringGrid.ColCount := ExcelLastCol - ExcelFirstCol + StringGridFirstCol + 1; StringGrid.RowCount := ExcelLastRow - ExcelFirstRow + StringGridFirstRow + 1; End; If ClearStringGridFirst Then Begin C := StringGrid.ColCount; R := StringGrid.RowCount; StringGrid.ColCount := 1; StringGrid.RowCount := 1; StringGrid.Cells[0,0] := ''; StringGrid.ColCount := C; StringGrid.RowCount := R; End; Result := True; For R := ExcelFirstRow To ExcelLastRow Do Begin For C := ExcelFirstCol To ExcelLastCol Do Begin Try StringGrid.Cells[ C - ExcelFirstCol + StringGridFirstCol, R - ExcelFirstRow + StringGridFirstRow] := Excel.Cells[R, C]; Except Result := False; End; End; End; End;
Delphi-Quellcode:
ExcelCopyToStringGrid( {hier ist mein problem} ,1,1,10,5,Stringgrid1,1,1,true,true);
|
Re: Was ist eine variable "Variant"
Ich sehe da kein Problem. Die Funktion erwartet eben als ersten Parameter einen Variable vom Typ
![]() |
Re: Was ist eine variable "Variant"
Ich würde fast glauben, Excel ist ein Automatisierungsobjekt (OleObject), das heisst eine Instanz von Excel.
Du kannst in einen Variant schliesslich auch Objekte (in dem Fall ein COM-Objekt) reinpacken. |
Re: Was ist eine variable "Variant"
und was ist nun wieder ein com-object?
|
Re: Was ist eine variable "Variant"
Zitat:
![]() Zitat:
Du musst Dir dann ja vorher bereits den Excel-COM-Server instanziert haben und dort das entsprechende Sheet geöffnet haben bevor Du die Daten in das Stringgrid reinbekommen kannst. |
Re: Was ist eine variable "Variant"
Hallo,
ein Variant ist noch viel mehr wie nur ein Datentyp. Ab Delphi 6 besteht damit auch die Möglichkeit von Operatorüberladung... Da gehen dann (man staune :shock:) sogar so Berechnungen wie
Delphi-Quellcode:
Ist das nicht toll 8)
c1 := VarComplexCreate('1+2i') ;
c2 := VarComplexCreate(3-4i) ; c := c1 * c2 ; // -> liefert dir 11 + 2i Gruß |
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:53 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