このようなソースなんですが、
procedure TForm.Activate(Sender: TObject);
type
t=array[1..100] of double;
var
I:integer;
FilesListView: TListView;
CurrentPositionTime:t;
begin
FilesCount:=100;
//フォーム上のボタンをすべて破棄
for I:=1 to FilesCount do
if Assigned(FButton[I]) then
FreeAndNil(FButton[I]);
//現在メディアプレイヤーで見ている動画のファイル名とリストに格納している動画ファイルのファイル名が一致したときに、その動画を見ていたまでの時間をCurrentPositionTimeに格納する。
for I:=1 to FilesCount do
if WindowsMediaPlayer.URL=FilesListView.Items[I].Caption then
CurrentPositionTime[I]:=WindowsMediaPlayer.Controls.CurrentPosition;
//CurrentPositionTimeが60秒以上の場合、ボタンを作成する。
for I:=1 to FilesCount do
if CurrentPositionTime[I]>=60 then
begin
FButton[I]:=TButton.Create(self);
FButton[I].Parent:=Form;
FOwnerDrawButton[I].Left:=34;
FOwnerDrawButton[I].Top:=34;
end;
end;
ActiveXで作成したメディアプレイヤーをループモードにしているので、
動画を見終わったときに先頭に戻るため、CurrentPositionTimeに0秒から代入されます。
そして、FormをActiveにしたときに上のソースが実行されるのですが、
コントロール"は親ウィンドウを持っていませんとエラーが出てしまいます。
少々分かりにくい点がありまして、見にくいソースですがどうか教えていただけないでしょうか??
FOwnerDrawButton[I].Left:=34;
FOwnerDrawButton[I].Top:=34;
は
FButton[I].Left:=34;
FButton[I].Top:=34;
でした。すみませんm_ _m
> FButton[I].Parent:=Form;
このFormが、どのFormであるか知りませんが、Activeになるフォーム上に
置きたいのであれば、「Self」にしたら?
FButton[I].Parent:=Self;
ほかにもあるぞw
var にある
FilesListView: TListView;
にアクセスしたらエラーだろ?
for I:=1 to FilesCount do
if WindowsMediaPlayer.URL=FilesListView.Items[I].Caption then
しかも Items は Items[I-1] にしないと駄目だろ?
投稿用に書き直したんだろうけど、投稿した部分だけでエラー出るのか?(違うエラーは出るだろうけど)
自分で書き直したのを実行したけどエラーにはならなかったぞ?
>>ofZさん
返信ありがとうございます。
試してみましたがやっぱり同じエラーが出てしまいました。
>>KHE00221さん
はい、おっしゃる通り投稿用に少し書きなおしました><
もう少し元ソースっぽくするとこうなります。
procedure TFishEyeView.FormActivate(Sender: TObject);
var
MaxLength,I,J,K:integer;
function Roundoff(x: double): integer;
begin
if x>=0 then
Result:=Trunc(x+0.5)
else
Result:=Trunc(x-0.5);
end;
begin
FilesCount:=100;
if not(FilesCount=0) then
begin
MaxLength:=0;
for I:=1 to FilesCount do
if MainPage.WindowsMediaPlayer.URL=RemoteController.FilesListView.Items[I-1].Caption then
CurrentPositionTime[I]:=MainPage.WindowsMediaPlayer.Controls.CurrentPosition;
for I:=1 to FilesCount do
if MaxLength<Roundoff(CurrentPositionTime[I]) then
MaxLength:=Roundoff(CurrentPositionTime[I]);
for I:=1 to FilesCount do
begin
if Assigned(FOwnerDrawButton[I]) then
FreeAndNil(FOwnerDrawButton[I]);
if CurrentPositionTime[I]>=60 then
begin
if Assigned(FOwnerDrawButton[I])=False then
begin
FOwnerDrawButton[I]:=TOwnerDrawButton.Create(self);
FOwnerDrawButton[I].Parent:=FishEyeView;
FOwnerDrawButton[I].Font.Size:=12;
FOwnerDrawButton[I].Caption:=IntToStr(I);
end;
FOwnerDrawButton[I].Height:=34;
FOwnerDrawButton[I].Width:=34;
Randomize;
n:=Random(4);
case n of
0:
begin
Yaxis[I]:=Roundoff(CurrentPositionTime[I])*(ClientHeight div 2) div MaxLength;
for J:=0 to 9 do
if (J*ClientHeight div 20<=Yaxis[I]) and (Yaxis[I]<=(J+1)*ClientHeight div 20) then
begin
FOwnerDrawButton[I].Height:=FOwnerDrawButton[I].Height+J*5;
FOwnerDrawButton[I].Width:=FOwnerDrawButton[I].Width+J*5;
end;
for J:=1 to FilesCount do
for K:=0 to 9 do
if Yaxis[J]>=((ClientHeight*K) div 20) then
Xaxis[J]:=((ClientWidth*K) div 20)+Random(((ClientWidth*(20-K*2)) div 20)+1);
end;
1:
begin
Xaxis[I]:=Roundoff(CurrentPositionTime[I])*(ClientWidth div 2) div MaxLength;
for J:=0 to 9 do
if (J*ClientWidth div 20<=Xaxis[I]) and (Xaxis[I]<=(J+1)*ClientWidth div 20) then
begin
FOwnerDrawButton[I].Height:=FOwnerDrawButton[I].Height+J*5;
FOwnerDrawButton[I].Width:=FOwnerDrawButton[I].Width+J*5;
end;
for J:=1 to FilesCount do
for K:=0 to 9 do
if Xaxis[J]>=((ClientWidth*K) div 20) then
Yaxis[J]:=((ClientHeight*K) div 20)+Random(((ClientHeight*(20-K*2)) div 20)+1);
end;
2:
begin
Yaxis[I]:=abs((Roundoff(CurrentPositionTime[I])*(ClientHeight div 2) div MaxLength)-ClientHeight);
for J:=10 to 19 do
if (J*ClientHeight div 20<=Yaxis[I]) and (Yaxis[I]<=(J+1)*ClientHeight div 20) then
begin
FOwnerDrawButton[I].Height:=FOwnerDrawButton[I].Height+(19-J)*5;
FOwnerDrawButton[I].Width:=FOwnerDrawButton[I].Width+(19-J)*5;
end;
for J:=1 to FilesCount do
for K:=10 to 19 do
if Yaxis[J]>=(ClientHeight*K) div 20 then
Xaxis[J]:=((ClientWidth*(19-K)) div 20)+Random(((ClientWidth*(20-(19-K)*2)) div 20)+1);
end;
3:
begin
Xaxis[I]:=abs((Roundoff(CurrentPositionTime[I])*(ClientWidth div 2) div MaxLength)-ClientWidth);
for J:=10 to 19 do
if (J*ClientWidth div 20<=Xaxis[I]) and (Xaxis[I]<=(J+1)*ClientWidth div 20) then
begin
FOwnerDrawButton[I].Height:=FOwnerDrawButton[I].Height+(19-J)*5;
FOwnerDrawButton[I].Width:=FOwnerDrawButton[I].Width+(19-J)*5;
end;
for J:=1 to FilesCount do
for K:=10 to 19 do
if Xaxis[J]>=((ClientWidth*K) div 20) then
Yaxis[J]:=((ClientHeight*(19-K)) div 20)+Random(((ClientHeight*(20-(19-K)*2)) div 20)+1);
end;
end;
FOwnerDrawButton[I].Left:=Xaxis[I]-FOwnerDrawButton[I].Width;
if Xaxis[I]-FOwnerDrawButton[I].Width<0 then
FOwnerDrawButton[I].Left:=Xaxis[I];
FOwnerDrawButton[I].Top:=Yaxis[I]-FOwnerDrawButton[I].Height;
if Yaxis[I]-FOwnerDrawButton[I].Height<0 then
FOwnerDrawButton[I].Top:=Yaxis[I];
end;
end;
end;
end;
ぐは!これは見たくない長さのソースだ(^^ゞ
配列 FOwnerDrawButton の宣言は?
FOwnerDrawButton :array[1..100] of TOwnerDrawButton; のように、
確実に「FilesCount:=100」で使用しているだけの要素数確保してある?
また、宣言してある場所は?
自分なら、とりあえず、FOwnerDrawButtonあたりが、うさんくさそうなので、
以下のあたりでエラーを捕まえてみる。
> if Assigned(FOwnerDrawButton[I])=False then
> begin
> FOwnerDrawButton[I]:=TOwnerDrawButton.Create(self);
> FOwnerDrawButton[I].Parent:=FishEyeView;
> FOwnerDrawButton[I].Font.Size:=12;
> FOwnerDrawButton[I].Caption:=IntToStr(I);
> end;
try
> FOwnerDrawButton[I].Height:=34;
> FOwnerDrawButton[I].Width:=34;
except
ShowMessage(FOwnerDrawButton[I].Caption);
end;
ここでダメなら、FOwnerDrawButtonのサイズ、位置を変更しているとこを
片っ端から try〜except で囲んで、場所がわかるようにメッセージ表示するよ。
上から ShowMessage('1');ShowMessage('2'); ・・・のように。
>>ofZさん
FOwnerDrawButtonは
http://rakasaka.fc2web.com/delphi/odbtn.html
ここのソースを用いて、色が変わるボタンを使用しています。
あと、要素数確保は大丈夫です。
これからがんばって片っ端からtry〜except文で確認してみようと思います。
アドバイス頂きありがとうございます。
FOwnerDrawButtonを宣言した場所によっては、以下の初期化が必要なこともある
for I:=1 to FilesCount do FOwnerDrawButton[I]:= nil;
ツイート | ![]() |