![]() |
Datenbank: dBase • Zugriff über: BDE
Couldn't convert varient of type (NULL) into type (String)
Delphi-Quellcode:
Bei diesem Aufruf bekomme ich die im Topic genannte Fehlermeldung.
for count := 1 to Pred(Query2.RecordCount) do begin
hcode:='<tr>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+Query2.FieldValues['KLASSEN']+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+Query2.FieldValues['S']+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+Query2.FieldValues['FUER']+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+Query2.FieldValues['WER']+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+Query2.FieldValues['FACH']+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+Query2.FieldValues['RAUM']+'</font></td>'+sLineBreak+'<td width=37% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+Query2.FieldValues['BEMER_SCH']+'</font></td>'+sLineBreak+'</tr>'+sLineBreak; WriteLn(Datei, hcode); end; Zudem wird immer für alle Zeile nur der Inhalt der ersten Zeile ausgegeben. Hat da jemand eine Idee? |
Re: Couldn't convert varient of type (NULL) into type (Strin
Ein tabellenfeld hat den Wert NULL was in Delphi in etwa mit Nil vergleichbar ist, also keinen Wert.
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Kann Delphi dann nicht einfach akzeptieren, dass es nichts auszugeben gibt?
Wie kann ich das Problem beheben? |
Re: Couldn't convert varient of type (NULL) into type (Strin
Vor der Ausgabe auf die Null-Werte reagieren (.isNull)
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Moin Svenkan,
Du könntest Dir auch einfach eine Funktion bauen, der Du die Feldwerte übergibst, und die dann, je nach Inhalt einen für Dich verarbeitbaren Wert zurückgibt. |
Re: Couldn't convert varient of type (NULL) into type (Strin
Zitat:
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Ja so ähnlich, dort könntest du auf Null abfragen und ggf 0 oder '' zurückgeben. Bei anderen DBMS kann man das auch direkt in der Abfrage erledigen.
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Zitat:
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Zeig mal deinen geänderten Code
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Delphi-Quellcode:
for count := 1 to Pred(Query2.RecordCount) do begin
Query2.FieldValues['WER'].isNull; Query2.FieldValues['FUER'].isNull; Query2.FieldValues['RAUM'].isNull; Query2.FieldValues['BEMER_SCH'].isNull; |
Re: Couldn't convert varient of type (NULL) into type (Strin
Delphi-Quellcode:
if not Query2.FieldValues['WER'].isNull then ... else ...
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Ich hab das jetzt so gemacht:
Delphi-Quellcode:
Aber entweder bin ich zu blöd zu kapieren, wie das funktioniert oder es klappt so wirklich nicht..
hcode2:='<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+if not Query2.FieldValues['WER'].isNull then Query2.FieldValues['WER'] else empty+'</font></td>';
Zitat:
|
Re: Couldn't convert varient of type (NULL) into type (Strin
So geht es natürlich nicht.
Delphi-Quellcode:
function CheckNull( Field: TField; eValue: Variant):Variant;
begin if not Field.isNull then result := Field.Value else result := eValue; end; ... hcode:='<tr>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+CheckNull(Query2.FieldByName('KLASSEN'], 'empty'))+... |
Re: Couldn't convert varient of type (NULL) into type (Strin
Danke soweit schonmal!
Bin irgendwie immer noch nicht so ganz ausm PHP-Konzept raus.. Leider bekomme ich den gleichen fehler mit dem NULL-Dingens immer noch..:( Ich habe alles nach deinem Schema umgebaut.
Delphi-Quellcode:
Das erste Feld, welches leer (also nil) ist, wäre 'WER'. Und genau in der Zeile befindet sich dann auch wieder der Ausgabefehler.
hcode:='<tr>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+CheckNull(Query2.FieldByName('KLASSEN'), 'empty')+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+CheckNull(Query2.FieldByName('S'), 'empty')+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+CheckNull(Query2.FieldByName('FUER'), 'empty')+'</font></td>'+sLineBreak;
WriteLn(Datei, hcode); hcode2:='<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+CheckNull(Query2.FieldByName('WER'), 'empty')+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+CheckNull(Query2.FieldByName('FACH'), 'empty')+'</font></td>'+sLineBreak+'<td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+CheckNull(Query2.FieldByName('RAUM'), 'empty')+'</font></td>'+sLineBreak+'<td width=37% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> '+CheckNull(Query2.FieldByName('BEMER_SCH'), 'empty')+'</font></td>'+sLineBreak+'</tr>'; WriteLn(Datei, hcode2); |
Re: Couldn't convert varient of type (NULL) into type (Strin
Hast du mal im Debugger geschaut, wo dieser Fehler auftritt?
|
Re: Couldn't convert varient of type (NULL) into type (Strin
In der Zeile wo hcode2 geschrieben werden sollte.
|
Re: Couldn't convert varient of type (NULL) into type (Strin
In meiner Funktion
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Es ist genau die gleiche Stelle, wie vor dem Einbau deiner Funktion.
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Nein schau dir mal der Ablauf in der Funktion an.
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Sry wenn ich jetzt so blöd frage, aber..
wo gennau? :D Da gibts ziemlich viele Debugwindows.. |
Re: Couldn't convert varient of type (NULL) into type (Strin
Setz doch einen Breakpoint auf die Zeile mit 'Wer' und geh dann mit F7 weiter
|
Re: Couldn't convert varient of type (NULL) into type (Strin
OK, deine Funktion arbeitet das Programm komplett durch.
Aber dann wenn es in die nächste Zeile zum Schreiben des Codes aus 'hcode2' geht meckert er rum. Davor macht er alles ganz normal. |
Re: Couldn't convert varient of type (NULL) into type (Strin
Was wird zurückgegeben?
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Siehe Topic. ;)
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Nein, was liefert meine Funktion zurück, wenn du ihr eine Null-Feld übergibst?
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Über die Breakpoints, was du mir grade gesagt hast, kommt gar nichts zurück, bis eben der genannte Fehler auftritt.
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Aber du solltest im Einzelschrittmodus sehen, in welchen Zweig der If-Anweisung er verzweigt.
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Sorry, wenn ich irgendwas verpasst habe, aber wieso ersetzt Du nicht
Delphi-Quellcode:
durch
Query.FieldValues['xxx']
Delphi-Quellcode:
Dann hast Du die Probleme doch erst gar nicht. :gruebel:
Query.FieldByName('xxx').AsString
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Hallo,
ich möchte noch eine Lanze für die PageProducer-Komponenten brechen. Hier wäre eine Gelegenheit für den Einsatz von TDataSetPageProducer. Einfach das HTML-Template zuweisen:
XML-Code:
Und ein kleines Stück Code:<tr> <td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> <#FIELD name=KLASSEN></font></td> <td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> <#FIELD name=S></font></td> <td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> <#FIELD name=FUER></font></td> <td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> <#FIELD name=WER></font></td> <td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> <#FIELD name=FACH</font></td> <td width=9% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> <#FIELD name=RAUM></font></td> <td width=37% bgcolor=#666666><font color=#FFFFFF size=2 face=Arial> <#FIELD name=BEMER_SCH></font></td> </tr>
Delphi-Quellcode:
So richtig gut wird das ganze mit verketteten Producern.
procedure TDataModel.DataSetPageProducerHTMLTag(Sender: TObject; Tag: TTag;
const TagString: String; TagParams: TStrings; var ReplaceText: String); var fldName: string; producer: TDataSetPageProducer; begin producer := Sender as TDataSetPageProducer; if (Tag = tgCustom) and SameText(TagString, 'FIELD') then begin fldName := TagParams.Values['name']; if Assigned(producer.DataSet.Fields.FindField(fldName)) then ReplaceText := VarToStr(producer.DataSet.FieldValues[fldName]) else ReplaceText := Format('[?%s]', [fldName]); end; end; { ... } procedure TDemoForm.ButtonClick(Sender: TObject); begin with DataModel do begin Query.Open; while not Query.Eof do begin Memo.Lines.Add(DataSetPageProducer.Content); Query.Next; end; Query.Close; end; end; Darüber meditieren ihr solltet. Gute Nacht |
Re: Couldn't convert varient of type (NULL) into type (Strin
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:
Immerhin ist der Fehler schonmal weg. Wie bekomme ich es nun noch hin, dass nicht immer nur das selbe geschrieben wird, sondern jede Zeile auch das, was dafür in der Tabelle steht? |
Re: Couldn't convert varient of type (NULL) into type (Strin
Hast du das .Next vergessen?
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Das tut ja schon fast weh..:D
Genau das wars! Dankeschön Leute! Ihr habt mir wie immer super geholfen! Echt super Forum ;) (hoffentlich werd ich auch ma bald so gut wie ihr..) |
Re: Couldn't convert varient of type (NULL) into type (Strin
Was spricht gegen
Fieldbyname('BLA').asString ??? |
Re: Couldn't convert varient of type (NULL) into type (Strin
Zitat:
|
Re: Couldn't convert varient of type (NULL) into type (Strin
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:07 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