PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label inherited. Show all posts
Showing posts with label inherited. Show all posts

Sunday, June 26, 2022

[FIXED] How to call correctly base class constructor from inherited class in Delphi Phrism?

 June 26, 2022     class, compiler-errors, constructor, delphi-prism, inherited     No comments   

Issue

I have two classes - base class and inherited class as follows.

Base Class:

TAlarm = class(System.Object)
private:
protected:
public:
    constructor (tag:TTagname);
end;

inherited class:

  TAlarmMsg = class(TAlarm)
  public
    constructor (aname:string);
    method GetAlarmMsg:string; override;
    method SendMsg(msg:string);
  end;

constructors:

constructor TAlarm(tag:TTagname);
begin
  Tagname := tag;
end;

constructor TAlarmMsg(aname:string);
begin
  inherited TAlarm(aname); <========Here is my problem.
  name := aname.ToCharArray;
end;

No matter what or how I call or play around with inherited constructor, I keep getting the following error messages when I compile the source file.

- Self cannot be accessed before the inherited constructor has finished. And/OR - Cannot find appropriate constructor in base class so manual call to inherited is required

By the way, I have spent good half a day researching on this issue and have found good information online. Nothing helps so far. I even found the webpage that directly talks about constructors on Delphi Prism Wikipedia ( http://prismwiki.embarcadero.com/en/Constructors ).

So, how would you do it correctly? Thanks,


Solution

The statement inherited constructor(aName); should do it.



Answered By - Carlo Kok
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, April 27, 2022

[FIXED] how can I fix this weak warning? "The field doesn’t override an inherited getter or setter."

 April 27, 2022     dart, flutter, inherited, overriding, warnings     No comments   

Issue

It shows this: "The field doesn’t override an inherited getter or setter." And because of this issue I can't push my Code in Git as it fails on test and analyze.

Any suggestions on how I can solve it? I shifted _startDate and _endDate out of Override but now it shows: "The method doesn’t override an inherited method." for displayDatePicker.

import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:date_range_picker/date_range_picker.dart' as DateRagePicker;

class Datepicker extends StatefulWidget {
  @override
  _DatepickerState createState() => _DatepickerState();
}

class _DatepickerState extends State<Datepicker> {

  DateTime _startDate = DateTime.now();
  DateTime _endDate = DateTime.now().add(Duration(days: 7));
  @override

  Future displayDatePicker(BuildContext context) async {
    {
      final List<DateTime> picked = await DateRagePicker.showDatePicker(
          context: context,
          initialFirstDate: _startDate,
          initialLastDate: _endDate,
          firstDate: new DateTime(DateTime.now().year),
          lastDate: new DateTime(DateTime.now().year + 2));
      if (picked != null && picked.length == 2) {
        setState(() {
          _startDate = picked[0];
          _endDate = picked[1];
        });
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          RaisedButton(
            child: Text('select Date'),
            onPressed: () async {
              await displayDatePicker(context);
            },
            color: Colors.red,
            textColor: Colors.white,
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(18.0),
                side: BorderSide(color: Colors.red)),
          ),
          //Text("from:${_startDate}"),
          //Text("until:${_endDate}"),
          Text(
              "from:${DateFormat('MM/dd/yyyy').format(_startDate).toString()}"),
          Text("until:${DateFormat('MM/dd/yyyy').format(_endDate).toString()}")
        ],
      ),
    );
  }
}

Solution

displayDatePicker is not a method of State<Datepicker>, thus, we just need to remove the @override line above Future displayDatePicker:

  // remove this line ---> @override

  Future displayDatePicker(BuildContext context) async {
    {
      final List<DateTime> picked = await DateRagePicker.showDatePicker(
          context: context,
          initialFirstDate: _startDate,
          initialLastDate: _endDate,
          firstDate: new DateTime(DateTime.now().year),
          lastDate: new DateTime(DateTime.now().year + 2));
      if (picked != null && picked.length == 2) {
        setState(() {
          _startDate = picked[0];
          _endDate = picked[1];
        });
      }
    }
  }


Answered By - Stefano Amorelli
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing