Can someone can explain me why i receive sometime an Exception «Argument out of range» under the ios simulator when i execute the code below? on android i never get any error. I use Delphi berlin.
the functions where the error appear :
{**********************************************************************}
procedure Twin_WorkerThreadPool.Enqueue(const Value: Twin_WorkerThread);
begin
Tmonitor.Enter(fPool);
try
fPool.Add(Value);
fSignal.SetEvent;
finally
Tmonitor.Exit(fPool);
end;
end;
{********************************************************}
function Twin_WorkerThreadPool.Dequeue: Twin_WorkerThread;
begin
Tmonitor.Enter(self); // << only one thread can execute the code below
try
Tmonitor.Enter(fPool);
try
if Fpool.Count > 0 then begin
result := fPool[Fpool.Count - 1];
fPool.Delete(Fpool.Count - 1);
exit;
end;
fSignal.ResetEvent;
finally
Tmonitor.Exit(fPool);
end;
fSignal.WaitFor(Infinite);
Tmonitor.Enter(fPool);
try
result := fPool[Fpool.Count - 1]; // << exception argument out of range ? but how it's possible ?
fPool.Delete(Fpool.Count - 1);
finally
Tmonitor.Exit(fPool);
end;
finally
Tmonitor.exit(self);
end;
end;
Below the full source code :
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
Twin_WorkerThreadPool = class(TObject)
private
fPool: TObjectList<Twin_WorkerThread>;
fSignal: Tevent;
public
procedure Enqueue(const Value: Twin_WorkerThread);
function Dequeue: Twin_WorkerThread;
end;
{***********************************}
constructor Twin_WorkerThread.Create;
begin
FProc := nil;
FProcReadySignal := TEvent.Create(nil, false{ManualReset}, false, '');
FProcFinishedSignal := TEvent.Create(nil, false{ManualReset}, false, '');
inherited Create(False); // see http://www.gerixsoft.com/blog/delphi/fixing-symbol-resume-deprecated-warning-delphi-2010
end;
{***********************************}
destructor Twin_WorkerThread.Destroy;
begin
Terminate;
FProcReadySignal.setevent;
WaitFor;
FProcReadySignal.Free;
FProcFinishedSignal.Free;
inherited;
end;
{**********************************}
procedure Twin_WorkerThread.Execute;
begin
while True do begin
try
//wait the signal
FProcReadySignal.WaitFor(INFINITE);
//if terminated then exit
if Terminated then Break;
//execute fProc
if assigned(FProc) then FProc();
//signal the proc is finished
FProcFinishedSignal.SetEvent;
except
//hide the exception
end;
end;
end;
{**********************************************************}
procedure Twin_WorkerThread.ExecuteProc(const AProc: TProc);
begin
fProc := AProc;
FProcFinishedSignal.ResetEvent;
FProcReadySignal.SetEvent;
end;
{*****************************************************************}
procedure Twin_WorkerThread.ExecuteAndWaitProc(const AProc: TProc);
begin
fProc := AProc;
FProcFinishedSignal.ResetEvent;
FProcReadySignal.SetEvent;
FProcFinishedSignal.WaitFor(INFINITE);
end;
{********************************************************************}
constructor Twin_WorkerThreadPool.Create(const aThreadCount: integer);
var i: integer;
begin
fPool := TObjectList<Twin_WorkerThread>.create(false{aOwnObjects});
fSignal := TEvent.Create(nil, false{ManualReset}, false, '');
for I := 0 to aThreadCount - 1 do
fPool.Add(Twin_WorkerThread.Create)
end;
{***************************************}
destructor Twin_WorkerThreadPool.Destroy;
var i: integer;
begin
for I := 0 to fPool.Count - 1 do begin
fPool[i].disposeOf;
fPool[i] := nil;
end;
fPool.Free;
fSignal.Free;
inherited Destroy;
end;
{*********************************************************************}
procedure Twin_WorkerThreadPool.ExecuteAndWaitProc(const AProc: TProc);
var aThread: Twin_WorkerThread;
begin
aThread := Dequeue;
try
aThread.ExecuteAndWaitProc(aProc);
finally
Enqueue(aThread);
end;
end;
NOTE:
Just to explain a little better, remember it’s only on ios it’s not work, and if i add a sleep(1000) after the fSignal.resetEvent then it’s work :
Tmonitor.Enter(fPool);
try
if Fpool.Count > 0 then begin
result := fPool[Fpool.Count - 1];
fPool.Delete(Fpool.Count - 1);
exit;
end;
fSignal.ResetEvent;
sleep(1000);
finally
Tmonitor.Exit(fPool);
end;
fSignal.WaitFor(Infinite);
so it’s look like that the signal is not set to OFF just after doing fSignal.ResetEvent;
i m affraid it’s a bug in TEvent or Tmonitor
MrJone 6 / 6 / 8 Регистрация: 18.09.2014 Сообщений: 124 |
||||||||
1 |
||||||||
28.10.2014, 22:47. Показов 15372. Ответов 10 Метки нет (Все метки)
Проблема такая. У меня программа через FTP качает файл с данными о версии. Читает. Сравнивает. И если версии такая же что и у оригинала, то просто запускает дальнейшую программу. Если же не такая же, то удаляет все старые файлы (кроме программы обновления, та что работает), а потом скачивает все файлы. Посмотрите код. Скажите что не так.
Вот код Dll
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
28.10.2014, 22:47 |
Ответы с готовыми решениями: Ошибка: Argument out of range Argument out of range Argument is out of range Argument out of range 10 |
2649 / 2270 / 279 Регистрация: 24.12.2010 Сообщений: 13,723 |
|
28.10.2014, 23:01 |
2 |
Вот код Dll Чумовая dll) Стесняюсь спросить, а зачем
0 |
6 / 6 / 8 Регистрация: 18.09.2014 Сообщений: 124 |
|
28.10.2014, 23:05 [ТС] |
3 |
Чумовая dll) Я её сделал так. Для тренинга.
0 |
6 / 6 / 8 Регистрация: 18.09.2014 Сообщений: 124 |
|
28.10.2014, 23:08 [ТС] |
4 |
Вот такая штукенция вылетает при компиляции и нажатии на кнопку Break.
0 |
2649 / 2270 / 279 Регистрация: 24.12.2010 Сообщений: 13,723 |
|
28.10.2014, 23:11 |
5 |
На неё не смотрим А нахрена тогда привел ее код ?)
уже часа 2 бьюсь. Ну вот не хочет и всё Ну пройдись пошагово отладчиком по своему коду и выясни какая строка вызывает ошибку..
0 |
6 / 6 / 8 Регистрация: 18.09.2014 Сообщений: 124 |
|
28.10.2014, 23:18 [ТС] |
6 |
Ну пройдись пошагово отладчиком по своему коду и выясни какая строка вызывает ошибку.. Я ожидал чего то более понятно. Ну вообщем то друго выхода по всей видемости нету. Буду отладчиком искать
0 |
Модератор 3488 / 2611 / 741 Регистрация: 19.09.2012 Сообщений: 7,971 |
|
28.10.2014, 23:20 |
7 |
Цикл задан неверно.
1 |
6 / 6 / 8 Регистрация: 18.09.2014 Сообщений: 124 |
|
28.10.2014, 23:26 [ТС] |
8 |
Цикл задан неверно. можете объяснить что не так?
0 |
Модератор 3488 / 2611 / 741 Регистрация: 19.09.2012 Сообщений: 7,971 |
|
28.10.2014, 23:29 |
9 |
Решение
что не так? Старший эл-т дин. массива имеет индекс Count-1.
1 |
volvo Супер-модератор 32582 / 21053 / 8131 Регистрация: 22.10.2011 Сообщений: 36,326 Записей в блоге: 8 |
||||
28.10.2014, 23:30 |
10 |
|||
У тебя тут вылет за пределы коллекции. Все коллекции индексируются от 0 до Count — 1…
1 |
6 / 6 / 8 Регистрация: 18.09.2014 Сообщений: 124 |
|
28.10.2014, 23:33 [ТС] |
11 |
Вам покажется странным, но у меня отказывает в доступе к папку где находиться программа Добавлено через 1 минуту
0 |
When you have generated a Server and a client Project.
When launching the client, you can «Get» the table content, if you try to refresh the data you will get an Argument out of range exception.
Delphi 10.3.1 SQL Server database.
When you get all tables, all tables are checked, but when you have about 300 tables in your database and if you need only 3 tables it’s a pain to check only those you don’t want.
It would ne nice to have a check all/ uncheck all function in the tool.
amazing work.
Workaround:
If you experience a EArgumentOutOfRangeException copy the Delphi FMX.Grid.Style.pas source file to your project directory and change the two raise lines in the CellRect event to Exit as follows:
function TStyledGrid.CellRect(const ACol, ARow: Integer): TRect;
var
I, X, Y: Integer;
HiddenFound: Boolean;
begin
if (ACol < 0) or (ACol > ColumnCount) then
Exit;//raise EArgumentOutOfRangeException.CreateResFmt(@SInvalidColumnIndex, [ACol]);
if (ARow < 0) or (ARow > RowCount) then
Exit;//raise EArgumentOutOfRangeException.CreateResFmt(@SInvalidRowIndex, [ARow]);
Thanks for your reply.
Unfortunatelly it doesn’t solve the problem.
I still get the error.
But When I add an exit on this line I have no error :
procedure TMainForm.RefreshTable;
var
I: Integer;
ColumnCount: Integer;
ColumnWidth: Integer;
begin
if Closing then Exit;
--->exit;
Добрый день!
Установил XE8, открыл проект собранный на XE7
начались проблемы со стилями (если использовать один стиль на всех формах), это пол беды. пришлось стиль новый для каждой формы ставить…
а ошибка что в названии появилась откуда не ждал, есть TListView, заполняется динамически
1-зачение добавляем
ListView1.ClearItems; with ListView1.Items.Add do begin Text := 'KCell'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'kcell.png')); Tag := 3; end; with ListView1.Items.Add do begin Text := 'Activ'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'activ.png')); Tag := 391; end; with ListView1.Items.Add do begin Text := 'Tele2'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'tele2.png')); Tag := 125; end; with ListView1.Items.Add do begin Text := 'Pathword'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'pathword.png')); Tag := 73; end; with ListView1.Items.Add do begin Text := 'Beeline'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'beeline.png')); Tag := 90; end; with ListView1.Items.Add do begin Text := 'ДОС'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'beeline-dos.png')); Tag := 578; end; with ListView1.Items.Add do begin Text := 'Dalacom'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'dalacom.png')); Tag := 12; end; with ListView1.Items.Add do begin Text := 'City'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'city.png')); Tag := 134; end; with ListView1.Items.Add do begin Text := 'ALTEL 4G'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'altel4g.png')); Tag := 716; end; with ListView1.Items.Add do begin Text := 'АО "Казахтелеком"'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'telecom.png')); Tag := 0; end;
2-значение
ListView1.ClearItems; with ListView1.Items.Add do begin Text := 'ALTEL 4G'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'altel4g.png')); Tag := 716; end; with ListView1.Items.Add do begin Text := 'JET'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'jet.png')); Tag := 484; end; with ListView1.Items.Add do begin Text := '"Интернет Дома" от Beeline'; Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'internetdoma.png')); Tag := 413; end;
моделируем ситуацию
если грузим 1 значение и тыкаем (выделяем) на последний или больший 2 itemindex
затем выполняем 2 значение, то выскакивает
argument out of range
т.е. получается ItemIndex или Selected Item не сбрасывается.
как эту ошибку исправить?
Totally different, these two have nothing to do with each other except that
they both involved a TList<T>
Also don’t think this has anything to do with NexusDB specifically.
Looking at the code of TDataSet.DataEvent the most likely reason I can see for
this to occur is this loop:
if NotifyDataSources then
begin
for I := 0 to FDataSources.Count — 1 do
FDataSources[i].DataEvent(Event, Info);
if FDesigner <> nil then FDesigner.DataEvent(Event, Info);
end;
During the execution of DataSources[i].DataEvent a number of events at the
TDataSource level could be called and the call is further cascading via
datalinks to all connected db-aware controls, where there are also many
opportunities for code to be executed.
If anywhere in that code at least two TDataSources that are currently connected
to that dataset are being freed or even just disconnected from the dataset,
it’s possible for the next iteration of the loop to attempt to acccess
FDataSources beyond it’s upper end (as the loop iterates all items based on the
initial count of the list, and is not designed to handle cases where the list
changes during iteration, while at the same time each iteration of the loop can
potentially call out to arbitrary user code, which might result in changes to
the list).
Will Owyong wrote:
> On 13/06/2017 8:12 PM, Roberto Nicchi wrote:
> > I’m receiving (by Eurekalog) the exception below.
> > Any idea what coud be the cause ?
> > NexusDb 4.12.01, Delphi XE10.1 update 2
> >
> > thanks
> >
> >
> > Argument out of range.
> >
> >
> > [00475591] System.Generics.Collections.TListHelper.CheckItemR ange
> > [007DB9C4] Data.DB.TDataSet.DataEvent
> > [00B16044] nxdb.TnxDataset.DataEvent (Line 8859, «nxdb.pas»)
> > [00B1C992] nxdb.TnxIndexDataSet.DataEvent (Line 11458, «nxdb.pas»)
> > [007D8EC4] Data.DB.TDataSet.SetState
> > [007D9348] Data.DB.TDataSet.SetActive
> > [00B1B5D0] nxdb.TnxDataset.SetActive (Line 11005, «nxdb.pas»)
> > [007D9135] Data.DB.TDataSet.Close
> > [007D89A6] Data.DB.TDataSet.Destroy
> > [00501E6A] System.Classes.TComponent.Notification
> > [755F7885] USER32.DispatchMessageW
> > [0077B853] Vcl.Forms.TApplication.ProcessMessage
> > [0077B896] Vcl.Forms.TApplication.HandleMessage
> > [0077BBC9] Vcl.Forms.TApplication.Run
> > [03298390] oroplus.Initialization (Line 1960, «oroplus.dpr»)
> > [770E3368] kernel32.BaseThreadInitThunk
>
>
> I’ve seen a similar error which was caused by changing screen resolution
> scale to 125%. As soon as I changed it back to 100% it disappeared.
>
> NXDB 4.12.01 and Delphi Berlin 10.1 update 1
>
>
> Exception: EArgumentOutOfRangeException
> Message: Argument out of range
> …..
> —————————————————————
> Callstack (Frames):
> [004531B1] System.Generics.Collections.TListHelper.CheckItemR ange (Line 1158,
> «System.Generics.Collections.pas») [00A78414]
> Vcl.Grids.TCustomGrid.ColWidthsChanged (Line 5284, «Vcl.Grids.pas»)
> [00A774E3] Vcl.Grids.TCustomGrid.SetColWidths (Line 4742, «Vcl.Grids.pas»)
> [00A711EE] Vcl.Grids.TCustomGrid.ChangeScale (Line 1714, «Vcl.Grids.pas»)
> [00DF77C7] Vcl.DBGrids.TCustomDBGrid.ChangeScale (Line 2421,
> «Vcl.DbGrids.pas») [0055EEAA] Vcl.Controls.TControl.ScaleForPPI (Line 6002,
> «Vcl.Controls.pas»)
> ================================================== ============
>
>
>
> Regards,
> Will