Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Was ist eine variable "Variant" (https://www.delphipraxis.net/27196-ist-eine-variable-variant.html)

NikoMitDaMacht 5. Aug 2004 18:23


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 function

Luckie 5. Aug 2004 18:25

Re: Was ist eine variable "Variant"
 
Delphi-Referenz durchsuchenVariant ist ein Datentyp. Näheres dazu findest du in der Delphi-Hilfe.

Phoenix 5. Aug 2004 18:29

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;

NikoMitDaMacht 5. Aug 2004 18:34

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?

NikoMitDaMacht 5. Aug 2004 18:42

Re: Was ist eine variable "Variant"
 
@Phoenix: vielen dank..
..aber das hilft mir leider nicht weiter bei meinen Problem mit folgender function

Delphi-Quellcode:
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;
Ich will damit ein excel worksheet in ein stringgrid machen :
Delphi-Quellcode:
ExcelCopyToStringGrid( {hier ist mein problem} ,1,1,10,5,Stringgrid1,1,1,true,true);

Luckie 5. Aug 2004 19:05

Re: Was ist eine variable "Variant"
 
Ich sehe da kein Problem. Die Funktion erwartet eben als ersten Parameter einen Variable vom Typ Delphi-Referenz durchsuchenVariant.

Phoenix 5. Aug 2004 19:05

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.

NikoMitDaMacht 5. Aug 2004 19:56

Re: Was ist eine variable "Variant"
 
und was ist nun wieder ein com-object?

Phoenix 5. Aug 2004 20:03

Re: Was ist eine variable "Variant"
 
Zitat:

Zitat von NikoMitDaMacht
und was ist nun wieder ein com-object?

Ich verstehe den Sinn der Frage nicht: Denn das solltest Du eigentlich wissen, wenn du (Zitat:) diese function (Zitat ende) verwenden willst.
Zitat:

Zitat von Quelltextkommentar
{!~Copies a range of Excel Cells to a Delphi StringGrid. If successful
True is returned, False otherwise. If SizeStringGridToFit is True
then the StringGrid is resized to be exactly the correct dimensions to
receive the input Excel cells, otherwise the StringGrid is not resized.
If ClearStringGridFirst is true then any cells outside the input range
are cleared, otherwise existing values are retained. Please not that the
Excel cell coordinates are "1" based and the Delphi StringGrid coordinates
are zero based.}

Du übergibst ein Excel-Sheet an die Funktion und die packt Dir die Daten in ein Stringgrid.

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.

Jelly 5. Aug 2004 21:54

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:
c1 := VarComplexCreate('1+2i') ;
c2 := VarComplexCreate(3-4i) ;
c := c1 * c2 ; // -> liefert dir 11 + 2i
Ist das nicht toll 8)

Gruß


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:53 Uhr.
Seite 1 von 2  1 2      

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