![]() |
Function Pointer in Array?
Moin,
ich hoffe das ist die richtige Kategorie hier. Ich bin immer noch an meinem Dienst dran, und ärgere mich gerade über meinen if-then-elseif-Code. Beispiel:
Delphi-Quellcode:
Nun kann man in C hier wunderbar mit Pointern etc arbeiten, um dieses doch entsprechend "schöner" zu gestalten.if (AnsiSameText(aCmd, 'GET_STOCK_POSITION')) then begin if (not(erp.GetStockPosition(Fetch(aActLine), sResult))) then begin WriteTCPLn(AContext, '001 Not found'); AddLog(erp.GetErrorMessages); end else begin WriteTCPLn(AContext, '000 '+sResult); erp.ClearErrorMessages; end; Exit; end else if (AnsiSameText(aCmd, 'GET_ARTICLENR_BY_BARCODE')) then begin if (not(erp.GetArticleNrByBarcode(Fetch(aActLine), sResult))) then begin WriteTCPLn(AContext, '001 Not found'); AddLog(erp.GetErrorMessages); end else begin WriteTCPLn(AContext, '000 '+sResult); erp.ClearErrorMessages; end; Exit; end; Kann man sowas auch in Delphi machen (Da der Aufruf eigentlich immer gleich ist)? Also sowas wie (Schematisch):
Delphi-Quellcode:
Meine Bastelei mit Pointern und einen type auf prodecdure of object führte nicht zum Erfolg.
aCommands = array[x..x]
( ('GET_STOCK_POSITION', erp.GetStockPosition, RESULT_IS_STRING), ('GET_ARTICLENR_BY_BARCODE', erp.GetArticleNrByBarcode, RESULT_IS_STRING), ('GET_STOCK_COUNT', erp.GetStockCount, RESULT_IS_INT) ) Entweder funktionierte es gar nicht, oder ich habe im Compiler immer schöne E2009-Meldungen bekommen, dass die Typen nicht übereinstimmen. Auch hier Beispiele/Hinweise sind gerne gesehen. :) Sonnige Grüsse, easy |
AW: Function Pointer in Array?
Es wäre zuckersüß von dir, wenn du Delphi-Code mit den DELPHI Tags versehen könntest.
Statt
Code:
käme dann
begin
foo := 'Hallo'; end;
Delphi-Quellcode:
Edit Danke :mrgreen:
begin
foo := 'Hallo'; end; |
AW: Function Pointer in Array?
Zitat:
Ich werde versuch beim nächsten Post mit Source dran zu denken. ;) |
AW: Function Pointer in Array?
passt nicht ganz für Deine Anfrage, ich habe eine meine ich ähnliches Problem folgendermassen gelöst, nur Auzüge aus dem Code....
Delphi-Quellcode:
Type
TKapaBlockSetter= procedure(const Value: Double) of Object; end; C_QueryKinds : Array [0..11] of String=('Retrostd. Vergangenheit','Echtaufträge','Rückstand','Planaufträge','Planaufträge verkauft' ,'ET/Umbau' ,'IST-Zeiten' ,'Angebot lt. Meisterliste' ,'Angebot durchschnittlich' ,'GK-Stunden' ,'Echtaufträge verg.' ,'GK-Stunden verg'); C_Setters : Array [0..11] of TMethod=((code:@TKapaAuswertung.SetRetroStdVerg;data:nil), (code:@TKapaAuswertung.SetEchtAuftr;data:nil), (code:@TKapaAuswertung.SetRueckVerteilt;data:nil), (code:@TKapaAuswertung.SetPlanAuftr;data:nil), (code:@TKapaAuswertung.SetPlanAuftrVerk;data:nil), (code:@TKapaAuswertung.SetETUmbau;data:nil), (code:@TKapaAuswertung.SetISTAnwesenheit;data:nil), (code:@TKapaAuswertung.SetAngebLtMeister;data:nil), (code:@TKapaAuswertung.SetAngebAVG;data:nil), (code:@TKapaAuswertung.SetGK_Stunden;data:nil), (code:@TKapaAuswertung.SetEchtAuftrverg;data:nil), (code:@TKapaAuswertung.SetGK_StundenVerg;data:nil) ); //im Code dann: var setter:TKapaBlockSetter; begin ... ... For i := Low(C_QueryKinds) to High(C_QueryKinds) do begin GetHelpQuery(Ads,'[P_GetKapaNeu]' + QuotedStr( C_QueryKinds[i]).............. TMethod(Setter).code := C_Setters[i].code; TMethod(Setter).data := FKapaAuswertung; Setter( Ads.Fields[1].AsFloat); end; |
AW: Function Pointer in Array?
oder auch so (ohne Pointer Gedöns)
Delphi-Quellcode:
var
res : Boolean; begin case IndexText( aCmd, [ 'GET_STOCK_POSITION', 'GET_ARTICLENR_BY_BARCODE' ] ) of 0 : res := erp.GetStockPosition( Fetch( aActLine ), sResult ); 1 : res := erp.GetArticleNrByBarcode( Fetch( aActLine ), sResult ); end; if not res then begin WriteTCPLn( AContext, '001 Not found' ); AddLog( erp.GetErrorMessages ); end else begin WriteTCPLn( AContext, '000 ' + sResult ); erp.ClearErrorMessages; end; end; |
AW: Function Pointer in Array?
Hi,
Man könnte sowas auch mit einem
Delphi-Quellcode:
lösen. Bzw. statt Pointer evtl. einen Methodenzeiger.
TDictionary<String,Pointer>
|
AW: Function Pointer in Array?
Zitat:
Danke. :) |
AW: Function Pointer in Array?
Aber nur bei aktueller Delphi-Version
|
AW: Function Pointer in Array?
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:17 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