Dear List, Trying to add 7Zip compression support to my delphi application. I am using the ported 7Zip sdk (see their website, they have a link). I am stumped on how to rewrite a single function: function ReverseDecode(var Models: array of SmallInt; ....): ..... where the input is mostly a fixed size array of SmallInt. This code perfectly compiles and functions in Delphi 6 and up, but in Delphi 5 I get the error: There is no overloaded version of 'ReverseDecode' that can be called with these arguments And obviously, the input (fixed) isn't the same as the param definition (dynamic sized). However, my question is just as obvious: How do I rewrite this function so it will behave correctly in Delphi 5? (If this is even possible) I hope I don't have to overload it to something like: function ReverseDecode(var Models: array[0..xxx] of SmallInt....... Thanks in advance for any assistance, Rory
![]() |
0 |
![]() |
Rory Slegtenhorst wrote: > Dear List, > > Trying to add 7Zip compression support to my delphi application. > I am using the ported 7Zip sdk (see their website, they have a link). > > I am stumped on how to rewrite a single function: > > function ReverseDecode(var Models: array of SmallInt; ....): ..... > > where the input is mostly a fixed size array of SmallInt. > This code perfectly compiles and functions in Delphi 6 and up, but in > Delphi 5 I get the error: There is no overloaded version of > 'ReverseDecode' that can be called with these arguments Is this version of the function part of a set of overloaded versions? If so, show the others, with full parameter lists please. > And obviously, the input (fixed) isn't the same as the param > definition (dynamic sized). Your parameter is *not* a dynamic array type, it is an open array parameter. Such a parameter can be passed any variable that is a fixed-size array of the same base type. It cannot be passed a dynamic array type in older Delphi versions, like D5 and 6, if memory serves. > However, my question is just as obvious: > How do I rewrite this function so it will behave correctly in Delphi > 5? (If this is even possible) Insufficient information, see my request above. D5 did have a number of limitations in the way the compiler handled overloaded functions/methods, these became progressively less in later versions. > I hope I don't have to overload it to something like: > function ReverseDecode(var Models: array[0..xxx] of SmallInt....... That would not be a valid declaration anyway, you would need a separate type declaration for the array type. The low-level approach would be an untyped parameter, but in this case you must pass the actual size of the array as a separate parameter since the function would not be able to figure out how much space the array has on its own. -- Peter Below (TeamB) Don't be a vampire (http://slash7.com/pages/vampires), use the newsgroup archives : http://codenewsfast.com http://groups.google.com
![]() |
0 |
![]() |
Dear Peter, It is a single function defined as: function ReverseDecode(var Models: array of smallint; const startIndex:integer;const rangeDecoder:TRangeDecoder; const NumBitLevels:integer):integer;overload; It then calls this function as rep0 := rep0 + UBitTreeDecoder.ReverseDecode(m_PosDecoders, rep0 - posSlot - 1, m_RangeDecoder, numDirectBits); Where rep0: Integer // local variable posSlot: Integer // local variable numDirectBits: Integer // local variable m_PosDecoders: array [0..ULZMABase.kNumFullDistances - ULZMABase.kEndPosModelIndex-1] of smallint; //private field of the class calling the function m_RangeDecoder:TRangeDecoder; // private field of the class calling the function At first I thought to be smart, and remove 'var' from Models, but then the decode function doesn't work anymore. For the time being I have solved this little puzzle by defining the Models parameter as a specific type and by introducing another local variable lArr of that type. Before and after it calls the function, I copy the data from and to m_PosDecoders/lArr: definitions: TSmallIntArray = array of SmallInt; function ReverseDecode(var Models: TSmallInt; const startIndex:integer;const rangeDecoder:TRangeDecoder; const NumBitLevels:integer):integer;overload; using it: SetLength(lArr, SizeOf(m_PosDecoders); Move(m_PosDecoders[0], lArr[0], SizeOf(m_PosDecoders)); // Copy m_PosDecoders to lArr rep0 := rep0 + UBitTreeDecoder.ReverseDecode(lArr, rep0 - posSlot - 1, m_RangeDecoder, numDirectBits); Move(lArr[0], m_PosDecoders[0], SizeOf(m_PosDecoders)); // Copy lArr back to m_PosDecoders SetLength(lArr, 0); This compiles in both D5 and D7, in addition that it properly works. This part of the code is vital for proper decoding 7Zip data lol I am aware of the subtle differences between D5 and D7, but I didn't expect this though. I truly hope I don't run into a lot of these ;) *grins* Rory
![]() |
0 |
![]() |
Rory Slegtenhorst wrote: > function ReverseDecode(var Models: array of smallint; const > startIndex:integer;const rangeDecoder:TRangeDecoder; const > NumBitLevels:integer):integer;overload; Hm, yes, that should be valid with the variable declarations you have shown. So this is likely a D5 limitation. Glad you found a workaround. -- Peter Below (TeamB) Don't be a vampire (http://slash7.com/pages/vampires), use the newsgroup archives : http://codenewsfast.com http://groups.google.com
![]() |
0 |
![]() |
Rory Slegtenhorst wrote: > > It is a single function defined as: > > function ReverseDecode(var Models: array of smallint; const > startIndex:integer;const rangeDecoder:TRangeDecoder; const > NumBitLevels:integer):integer;overload; If it really is just a single function, why is it declared 'overload'? I made a small test program in D5, which gives your error message when 'overload' is there, but works as long as 'overload' is not specified. It looks like overload and open arrays do not work together in D5. {code} type tArr = array[0..10] of smallint; var iArr: tArr; procedure IncrementThemOpen(var a: array of smallint); {overload; doesn't work} var i: Integer; begin for i := Low(a) to High(a) do a[i] := a[i] + 1; end; procedure IncrementThemFixed(var a: tArr); overload; {fixed array and overload works} var i: Integer; begin for i := Low(a) to High(a) do a[i] := a[i] + 1; end; procedure TForm1.Button1Click(Sender: TObject); var sl: TStringList; i: Integer; s: string; begin sl := TStringList.Create; sl.CommaText := Edit1.Text; for i := 0 to Pred(sl.Count) do begin iArr[i] := StrToInt(sl[i]); end; IncrementThemOpen(iArr); IncrementThemFixed(iArr); s := IntToStr(iArr[0]); for i := 1 to Pred(sl.Count) do begin s := s + ', ' + IntToStr(iArr[i]); end; Edit2.Text := s; end;{code} -- Anders Isaksson, Sweden BlockCAD: http://web.telia.com/~u16122508/proglego.htm Gallery: http://web.telia.com/~u16122508/gallery/index.htm
![]() |
0 |
![]() |
Dear Anders, > {quote:title=Anders Isaksson wrote:}{quote} > Rory Slegtenhorst wrote: > > > > > It is a single function defined as: > > > > function ReverseDecode(var Models: array of smallint; const > > startIndex:integer;const rangeDecoder:TRangeDecoder; const > > NumBitLevels:integer):integer;overload; > > If it really is just a single function, why is it declared 'overload'? > > I made a small test program in D5, which gives your error message when > 'overload' is there, but works as long as 'overload' is not specified. It > looks like overload and open arrays do not work together in D5. I never even saw the 'overload' directive (out of screen) until it was mentioned a second time here in the thread. I performed the same tests as you have done, and came to the same conclusion. Removing 'overload' simply corrected the whole thing. I am completely unsure as to why the function is declared as such, as it's the only function in the unit. Thank you very much for your assistance, Rory
![]() |
0 |
![]() |